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

Add empty and stacked indexes #346

Merged
merged 3 commits into from
May 13, 2024
Merged

Conversation

Ladicek
Copy link
Collaborator

@Ladicek Ladicek commented Dec 11, 2023

Fixes #142

@Ladicek Ladicek added this to the 3.2.0 milestone Dec 11, 2023
@Ladicek
Copy link
Collaborator Author

Ladicek commented Dec 11, 2023

Draft for now, because of the 3.2.0 target. Other than that, this should be ready.

*
* @since 3.2.0
*/
public final class EmptyIndex implements IndexView {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ehm, what is this for? I mean it's not even used internally, is it? And what's the benefit of this optimized empty version? Right now, there are other ways to obtain an empty index such as Index.of(Collections.emptyList()). Shouldn't we use the EmptyIndex in similar scenarios? Maybe we should add something like Index.empty()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So there's a difference between empty Index (which is fairly heavy-weight) and empty IndexView (which is super light-weight).

I don't have a use case for it myself, but apparently Hibernate Search people do: https://github.com/hibernate/hibernate-search/blob/main/util/common/src/main/java/org/hibernate/search/util/common/jar/impl/JandexUtils.java#L51 And it feels right to have a dedicated implementation directly in Jandex.

Copy link
Contributor

Choose a reason for hiding this comment

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

If so, then we should probably promote the API a bit more, i.e. mention/link it in the IndexView, maybe even add IndexView.empty() etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did contemplate about a public static IndexView empty() method on IndexView vs. a public class EmptyIndex and didn't feel strongly about either. I can switch to the static method for sure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added IndexView.empty().

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that it's ok to have both.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, agree, I didn't know why I didn't make EmptyIndex.INSTANCE public. Fixed.

}

/**
* Creates a stacked index from given {@code indexes}. The first element of the list is the bottom-most index
Copy link
Contributor

Choose a reason for hiding this comment

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

This means that when you build the stack you need to add the indexes with "lower priority" first which is IMO not exactly intuitive and practical. I wonder if we should offer some more flexible way of building the stack.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I actually had a push(IndexView) method implemented (that would return a new stacked index with the given argument on top of the stack), but I felt like a solution in search of a problem, so I ultimately removed it. It should be easy to re-add.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added StackedIndex.pushIndex().

@Ladicek Ladicek force-pushed the empty-stacked-index branch 2 times, most recently from 9244e6e to f21ce6b Compare December 13, 2023 11:15
A stacked index is a composition of multiple indices with overlay semantics.
Overlaying is done on class granularity. When the composition doesn't contain
duplicate classes (multiple classes with the same name), a `StackedIndex`
behaves just like a `CompositeIndex`, but when duplicates appear, the behavior
of `StackedIndex` is actually well defined.

This commit also adds a test for index navigation methods from `IndexView`,
as those have not been tested at all. Some tests reveal inconsistencies
in how `CompositeIndex` behaves in presence of duplicates, which is not nice,
but this commit intentionally doesn't modify `CompositeIndex` behavior.
@Ladicek Ladicek marked this pull request as ready for review May 13, 2024 11:46
@Ladicek Ladicek merged commit 5a892b0 into smallrye:main May 13, 2024
39 checks passed
@Ladicek Ladicek deleted the empty-stacked-index branch May 13, 2024 11:57
This pull request was closed.
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.

Add a "stacked" composite index
2 participants