CLIENT-4226 Support selecting secondary index by name hint#64
CLIENT-4226 Support selecting secondary index by name hint#64
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for explicitly selecting a secondary index by name (via IndexContext) when parsing DSL expressions, and extends test coverage to validate the new hint behavior and its fallbacks.
Changes:
- Introduce
IndexContext.of(namespace, indexes, indexToUse)to allow callers to request a specific index by name. - Add parsed-expression tests covering explicit index selection, fallback behavior (missing/null/empty hint), and interaction with
ORexpressions. - Add a test asserting that a top-level
ORnever produces an SI filter even if an explicit index is provided.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/main/java/com/aerospike/dsl/IndexContext.java |
Adds a new of(...) overload that narrows the index set to the requested index name when present. |
src/test/java/com/aerospike/dsl/parsedExpression/LogicalParsedExpressionTests.java |
Adds test cases validating explicit index selection and fallback semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * **`static IndexContext of(String namespace, Collection<Index> indexes)`**: Creates a context. | ||
| * `namespace`: The namespace the query will be run against. | ||
| * `namespace`: The namespace the query will be run against. Must not be null or blank. | ||
| * `indexes`: A collection of `Index` objects representing the available secondary indexes for that namespace. |
There was a problem hiding this comment.
The new 3-parameter IndexContext.of method with indexToUse parameter should be documented here. This is a public API addition that allows users to specify an index hint, which is a key feature mentioned in the PR title CLIENT-4226.
| // Create index context | ||
| IndexContext indexContext = IndexContext.of("namespace", List.of(cityIndex)); | ||
| // Create index context (namespace must not be null or blank) | ||
| IndexContext indexContext = IndexContext.of("test", List.of(cityIndex)); |
There was a problem hiding this comment.
Consider adding a section to this guide explaining how to use the new index hint feature with the 3-parameter IndexContext.of method. This would help users understand when and how to explicitly specify which secondary index to use, which is the main feature of this PR (CLIENT-4226).
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public static IndexContext of(String namespace, Collection<Index> indexes, String indexToUse) { | ||
| validateNamespace(namespace); | ||
| List<Index> matchingIndexes = indexes.stream() | ||
| .filter(idx -> indexMatches(idx, namespace, indexToUse)) | ||
| .toList(); | ||
| return new IndexContext(namespace, matchingIndexes.isEmpty() ? indexes : matchingIndexes); |
There was a problem hiding this comment.
IndexContext.of(namespace, indexes, indexToUse) calls indexes.stream() without guarding against indexes == null, which will throw a NPE (while the 2-arg of overload currently tolerates null and the parser treats it as empty). Either reject null indexes explicitly (with a clear IllegalArgumentException) or treat null as an empty collection here to keep overload behavior consistent.
| public static IndexContext withBinHint(String namespace, Collection<Index> indexes, String binToUse) { | ||
| validateNamespace(namespace); | ||
| if (binToUse == null || binToUse.isBlank()) { | ||
| return new IndexContext(namespace, indexes); | ||
| } | ||
| List<Index> matchingIndexes = indexes.stream() | ||
| .filter(idx -> binMatches(idx, namespace, binToUse)) | ||
| .toList(); | ||
| return new IndexContext(namespace, matchingIndexes.size() == 1 ? matchingIndexes : indexes); |
There was a problem hiding this comment.
IndexContext.withBinHint(...) calls indexes.stream() without guarding against indexes == null, which will throw a NPE. Consider either validating indexes is non-null (and failing fast with IllegalArgumentException) or treating null as an empty collection, consistent with how the parser treats a null index collection.
| private static boolean indexMatches(Index idx, String namespace, String indexToUse) { | ||
| if (idx == null || indexToUse == null) { | ||
| return false; | ||
| } | ||
|
|
||
| String indexName = idx.getName(); | ||
| if (indexName == null || !indexName.equals(indexToUse)) { | ||
| return false; | ||
| } | ||
|
|
||
| return namespace.equals(idx.getNamespace()); | ||
| } |
There was a problem hiding this comment.
indexMatches treats only null as “no hint”. The docs/Javadoc for IndexContext.of(..., indexToUse) state that an empty hint should trigger automatic selection, but passing "" can still match an index whose name is also "" (since Index.name isn’t validated). Consider ignoring blank/empty hints (indexToUse == null || indexToUse.isBlank()) so behavior matches the documented contract.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Uh oh!
There was an error while loading. Please reload this page.