Skip to content

CLIENT-4226 Support selecting secondary index by name hint#64

Open
agrgr wants to merge 9 commits intomainfrom
CLIENT-4226-support-secondary-index-hint
Open

CLIENT-4226 Support selecting secondary index by name hint#64
agrgr wants to merge 9 commits intomainfrom
CLIENT-4226-support-secondary-index-hint

Conversation

@agrgr
Copy link
Collaborator

@agrgr agrgr commented Feb 20, 2026

  • Support selecting secondary index by name using a hint
  • The fields namespace, bin, indexType, and binValuesRatio are made mandatory
  • Support selecting secondary index by bin name using a hint hint

@agrgr agrgr requested a review from Copilot February 20, 2026 14:40
@agrgr agrgr added the enhancement New feature or request label Feb 20, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 OR expressions.
  • Add a test asserting that a top-level OR never 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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 50 to 52
* **`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.
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
// 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));
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
agrgr and others added 4 commits February 24, 2026 22:57
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@agrgr agrgr requested a review from Copilot February 25, 2026 13:01
@agrgr agrgr changed the title CLIENT-4226 Support selecting secondary index name via a hint CLIENT-4226 Support selecting secondary index by name via a hint Feb 25, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 53 to 58
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);
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines 74 to 82
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);
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +107 to +118
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());
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@agrgr agrgr marked this pull request as ready for review February 25, 2026 13:28
@agrgr agrgr requested a review from tim-aero February 25, 2026 13:29
@agrgr agrgr changed the title CLIENT-4226 Support selecting secondary index by name via a hint CLIENT-4226 Support selecting secondary index by name hint Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants