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

HSEARCH-4577 @ProjectionConstructor: aggregating multi-valued field/object projections in Set, SortedSet, etc. instead of List #4344

Conversation

marko-bekhta
Copy link
Member

https://hibernate.atlassian.net/browse/HSEARCH-4577


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


@marko-bekhta marko-bekhta force-pushed the feat/HSEARCH-4577-ProjectionConstructor-aggregating-multi-valued-fieldobject-projections-in-Set-SortedSet-v2 branch 6 times, most recently from 18591e8 to 8619389 Compare October 4, 2024 14:04
@marko-bekhta marko-bekhta force-pushed the feat/HSEARCH-4577-ProjectionConstructor-aggregating-multi-valued-fieldobject-projections-in-Set-SortedSet-v2 branch 2 times, most recently from ee42a82 to 6b53306 Compare October 28, 2024 15:45
Copy link
Member

@yrodiere yrodiere left a comment

Choose a reason for hiding this comment

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

Just noticed this was still pending -- did you encounter any problem? Did I forget a review? :x

@marko-bekhta
Copy link
Member Author

Just noticed this was still pending -- did you encounter any problem? Did I forget a review? :x

Problems ? no no problems, only opportunities 😄.
From my notes I only have: take another look at the docs.

I suppose ProjectionCollector is a better name, but then people might wonder why we didn't just use java.util.stream.Collector. From the javadoc it's mainly because of unnecessary features in Collector and because of the transform stuff.

mm ok 😃 I can rename it 👍🏻 (it was good I left the PR hanging here 😄) So if we go with ProjectionCollector then corresponding .accumulator(...) methods become .collector(...) ? ooor ...

@yrodiere
Copy link
Member

yrodiere commented Nov 8, 2024

mm ok 😃 I can rename it 👍🏻 (it was good I left the PR hanging here 😄) So if we go with ProjectionCollector then corresponding .accumulator(...) methods become .collector(...) ? ooor ...

I guess that's what makes most sense, yes. collect(collector) would be closer to java.util.stream, but confusing since our method doesn't actually perform the collecting, which happens later.

BTW I wonder if we could just use java.util.stream.Collector :D Probably something to investigate in a different ticket, though -- if we even investigate it.

@marko-bekhta
Copy link
Member Author

I guess that's what makes most sense, yes. collect(collector) would be closer to java.util.stream, but confusing since our method doesn't actually perform the collecting, which happens later.

ok 😃, yeah that's what I thought too ... that we are not collecting in that particular place ...

BTW I wonder if we could just use java.util.stream.Collector :D Probably something to investigate in a different ticket, though -- if we even investigate it.

hah I was just looking at the collector interface 😄, but yeah I agree that it's for the other PR. But if we want to explore that option, should I mark ProjectionCollector as incubating for now? (if we end up replacing it with collector)

@marko-bekhta marko-bekhta force-pushed the feat/HSEARCH-4577-ProjectionConstructor-aggregating-multi-valued-fieldobject-projections-in-Set-SortedSet-v2 branch from 6b53306 to 2a56f99 Compare November 11, 2024 16:45
@yrodiere
Copy link
Member

should I mark ProjectionCollector as incubating for now? (if we end up replacing it with collector)

That's probably a good idea regardless of our plans, yes.

@marko-bekhta marko-bekhta force-pushed the feat/HSEARCH-4577-ProjectionConstructor-aggregating-multi-valued-fieldobject-projections-in-Set-SortedSet-v2 branch 3 times, most recently from 5793d12 to 6c94d65 Compare November 14, 2024 16:51
@marko-bekhta marko-bekhta marked this pull request as ready for review November 14, 2024 16:51
@marko-bekhta marko-bekhta force-pushed the feat/HSEARCH-4577-ProjectionConstructor-aggregating-multi-valued-fieldobject-projections-in-Set-SortedSet-v2 branch from 6c94d65 to 32db920 Compare November 15, 2024 13:47
@marko-bekhta marko-bekhta force-pushed the feat/HSEARCH-4577-ProjectionConstructor-aggregating-multi-valued-fieldobject-projections-in-Set-SortedSet-v2 branch from 32db920 to ef4706e Compare November 18, 2024 08:34
@marko-bekhta marko-bekhta merged commit 562065f into hibernate:main Nov 18, 2024
8 checks passed
@SuppressWarnings("unchecked")
@Override
public V[] doFinish(List<V> accumulated) {
V[] array = (V[]) Array.newInstance( elementType, accumulated.size() );
Copy link
Member Author

Choose a reason for hiding this comment

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

Soooo following the discussion at https://hibernate.zulipchat.com/#narrow/channel/132094-hibernate-orm-dev/topic/StandardStack.20and.20reflection
I guess this won't fly well with Quarkus too 😖 😃....

I can change this to use IntFunction<T[]> and simply use accumulated.toList( ... ) but then..... it won't work fine here:

else if ( containerType.isArray() ) {
reference = ProjectionCollector.array( containerElementType );
}

so we could do something like for sorted sets and throw an exception. Or give two ways to create array collector with class and with function. Use class in the ProjectionBindingContextImpl and it'll fail for users so they'd need to register their arrays themselves .... @yrodiere WDYT ? 🙈

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine-ish, as this only happens when a user explicitly requests an array, so it's reasonable to expect them to register that array type for reflection.

For ProjectionBindingContextImpl, I suppose we can add something to Quarkus that would detect projection constructors and register for reflection any array type used in their parameters. But only if we consider this important enough -- I personally don't. I wouldn't even have provided the feature TBH, because using arrays in domain models is a big no-no in my books. But now that it's there, I guess we might as well keep it.

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.

2 participants