Skip to content

Support accessing members of a conditional value #35390

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ranma42
Copy link
Contributor

@ranma42 ranma42 commented Dec 28, 2024

This changeset adds support for accessing a member of the result of a conditional expression.

It achieves this by folding the member access into the conditional.

Fixes #34589.

@ranma42
Copy link
Contributor Author

ranma42 commented Dec 28, 2024

Note that the updated baselines point to a missing CASE simplification (CASE WHEN nonNullableX THEN TRUE ELSE FALSE END -> nonNullableX).
Additionally, the test I implemented currently hits #28077 (neither join is really needed).

I would like to add a couple of missing test cases before marking as ready:

I am also thinking that it might be a good idea to write the tests so that they do not interact with #28077, so I will probably end up rewriting the existing test. What is the best place for these tests? (if I want to check the behavior on different subclasses, maybe InheritanceQueryTestBase makes more sense 🤔 )

@ranma42 ranma42 changed the title Support accessing a members of a conditional value Support accessing members of a conditional value Dec 28, 2024
The extended `LocustHorde` has two fields which have different types but share
the same base type. This is interesting when using SQL constructs to select one
of the two fields as they are compatible but have different types.
@ranma42
Copy link
Contributor Author

ranma42 commented Jan 6, 2025

I extended the tests and kept them in GoW, as the different handling of subclassing is interesting.
In order to implement Conditional_Navigation_With_Member_Access_On_Related_Types I extended LocustHorde, which has the unfortunate side-effects of changing unrelated tests (adding a column in several SELECT queries).
I would love recommendations on possible improvements.

@ranma42 ranma42 marked this pull request as ready for review January 6, 2025 16:41
@ranma42 ranma42 requested a review from a team as a code owner January 6, 2025 16:41
@Xriuk

This comment was marked as resolved.

@ranma42

This comment was marked as resolved.

@Xriuk
Copy link

Xriuk commented Mar 31, 2025

Just to add that this might be more complex: property/fields access might also include type casts in the chain.
Also it might be worth supporting comparison operators and also method invocations too (instance methods and static/extensions)?

@ranma42
Copy link
Contributor Author

ranma42 commented Mar 31, 2025

@Xriuk I will probably restrict this changeset to a more limited scope; the various types of expressions are (at least in part) handled by different translators, so to handle this in full generality some heavy restructuring of the translation pipeline might be needed.
In fact, this change does not even generalize in a trivial way to conditional navigations as used in your second example (the navigations are identified/expanded in a different visitor).
I did not yet push that changeset that includes that as a test it as I was hoping to get at least that part fixed in this PR, but maybe it's better to start by only covering the simple cases from the original issue 🤔

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.

Support projecting different navigations (but same type) via conditional operator
4 participants