Skip to content

Commit

Permalink
Make java compile task pass
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Gaievski <[email protected]>
  • Loading branch information
martin-gaievski committed Jan 28, 2025
1 parent 9799c6c commit cfde072
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 51 deletions.
19 changes: 12 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import java.util.concurrent.Callable

buildscript {
ext {
opensearch_version = System.getProperty("opensearch.version", "3.0.0-SNAPSHOT")
buildVersionQualifier = System.getProperty("build.version_qualifier", "")
opensearch_version = System.getProperty("opensearch.version", "3.0.0-alpha1-SNAPSHOT")
buildVersionQualifier = System.getProperty("build.version_qualifier", "alpha1")
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
version_tokens = opensearch_version.tokenize('-')
opensearch_build = version_tokens[0] + '.0'
Expand Down Expand Up @@ -250,13 +250,17 @@ def knnJarDirectory = "$buildDir/dependencies/opensearch-knn"

dependencies {
api "org.opensearch:opensearch:${opensearch_version}"
zipArchive group: 'org.opensearch.plugin', name:'opensearch-knn', version: "${opensearch_build}"
zipArchive group: 'org.opensearch.plugin', name:'opensearch-ml-plugin', version: "${opensearch_build}"
//TODO need to replace by ${opensearch_build} once dependencies adapt new core version
zipArchive group: 'org.opensearch.plugin', name:'opensearch-knn', version: "3.0.0.0-SNAPSHOT"
//TODO need to replace by ${opensearch_build} once dependencies adapt new core version
zipArchive group: 'org.opensearch.plugin', name:'opensearch-ml-plugin', version: "3.0.0.0-SNAPSHOT"
secureIntegTestPluginArchive group: 'org.opensearch.plugin', name:'opensearch-security', version: "${opensearch_build}"
compileOnly fileTree(dir: knnJarDirectory, include: "opensearch-knn-${opensearch_build}.jar")
//TODO need to replace by ${opensearch_build} once dependencies adapt new core version
compileOnly fileTree(dir: knnJarDirectory, include: "opensearch-knn-3.0.0.0-SNAPSHOT.jar")
compileOnly group: 'com.google.guava', name: 'guava', version:'32.1.3-jre'
compileOnly group: 'commons-lang', name: 'commons-lang', version: '2.6'
api group: 'org.opensearch', name:'opensearch-ml-client', version: "${opensearch_build}"
//TODO need to replace by ${opensearch_build} once dependencies adapt new core version
api group: 'org.opensearch', name:'opensearch-ml-client', version: "3.0.0.0-SNAPSHOT"
testFixturesImplementation "org.opensearch.test:framework:${opensearch_version}"
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.14.0'
// ml-common excluded reflection for runtime so we need to add it by ourselves.
Expand All @@ -273,7 +277,8 @@ dependencies {
testFixturesImplementation "org.opensearch:common-utils:${version}"
testFixturesImplementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.14.0'
testFixturesCompileOnly group: 'com.google.guava', name: 'guava', version:'32.1.3-jre'
testFixturesCompileOnly fileTree(dir: knnJarDirectory, include: "opensearch-knn-${opensearch_build}.jar")
//TODO need to replace by ${opensearch_build} once dependencies adapt new core version
testFixturesCompileOnly fileTree(dir: knnJarDirectory, include: "opensearch-knn-3.0.0.0-SNAPSHOT.jar")
}

// In order to add the jar to the classpath, we need to unzip the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private List<CompoundTopDocs> getCompoundTopDocs(CombineScoresDto combineScoresD
* @return max score
*/
private float maxScoreForShard(CompoundTopDocs updatedTopDocs, boolean isSortEnabled) {
if (updatedTopDocs.getTotalHits().value == 0 || updatedTopDocs.getScoreDocs().isEmpty()) {
if (updatedTopDocs.getTotalHits().value() == 0 || updatedTopDocs.getScoreDocs().isEmpty()) {
return MAX_SCORE_WHEN_NO_HITS_FOUND;
}
if (isSortEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void combineShardScores(
final CompoundTopDocs compoundQueryTopDocs,
final Sort sort
) {
if (Objects.isNull(compoundQueryTopDocs) || compoundQueryTopDocs.getTotalHits().value == 0) {
if (Objects.isNull(compoundQueryTopDocs) || compoundQueryTopDocs.getTotalHits().value() == 0) {
return;
}
List<TopDocs> topDocsPerSubQuery = compoundQueryTopDocs.getTopDocs();
Expand Down Expand Up @@ -292,7 +292,7 @@ private void updateQueryTopDocsWithCombinedScores(
boolean isSortingEnabled
) {
// - max number of hits will be the same which are passed from QueryPhase
long maxHits = compoundQueryTopDocs.getTotalHits().value;
long maxHits = compoundQueryTopDocs.getTotalHits().value();
// - update query search results with normalized scores
compoundQueryTopDocs.setScoreDocs(
getCombinedScoreDocs(
Expand All @@ -309,7 +309,7 @@ private void updateQueryTopDocsWithCombinedScores(

private TotalHits getTotalHits(final List<TopDocs> topDocsPerSubQuery, final long maxHits) {
TotalHits.Relation totalHits = TotalHits.Relation.EQUAL_TO;
if (topDocsPerSubQuery.stream().anyMatch(topDocs -> topDocs.totalHits.relation == TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO)) {
if (topDocsPerSubQuery.stream().anyMatch(topDocs -> topDocs.totalHits.relation() == TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO)) {
totalHits = TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO;
}
return new TotalHits(maxHits, totalHits);
Expand Down Expand Up @@ -343,7 +343,7 @@ private List<ExplanationDetails> explainByShard(
final CompoundTopDocs compoundQueryTopDocs,
final Sort sort
) {
if (Objects.isNull(compoundQueryTopDocs) || compoundQueryTopDocs.getTotalHits().value == 0) {
if (Objects.isNull(compoundQueryTopDocs) || compoundQueryTopDocs.getTotalHits().value() == 0) {
return List.of();
}
// create map of normalized scores results returned from the single shard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void rerank(
final ActionListener<SearchResponse> listener
) {
try {
if (searchResponse.getHits().getTotalHits().value == 0) {
if (searchResponse.getHits().getTotalHits().value() == 0) {
listener.onResponse(searchResponse);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public HybridQueryScorer(final Weight weight, final List<Scorer> subScorers) thr
}

HybridQueryScorer(final Weight weight, final List<Scorer> subScorers, final ScoreMode scoreMode) throws IOException {
super(weight);
super();
this.subScorers = Collections.unmodifiableList(subScorers);
this.numSubqueries = subScorers.size();
this.subScorersPQ = initializeSubScorersPQ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,6 @@ private Void addScoreSupplier(Weight weight, HybridQueryExecutorCollector<LeafRe
return null;
}

/**
* Create the scorer used to score our associated Query
*
* @param context the {@link LeafReaderContext} for which to return the
* {@link Scorer}.
* @return scorer of hybrid query that contains scorers of each sub-query, null if there are no matches in any sub-query
* @throws IOException
*/
@Override
public Scorer scorer(LeafReaderContext context) throws IOException {
ScorerSupplier supplier = scorerSupplier(context);
if (supplier == null) {
return null;
}
supplier.setTopLevelScoringClause();
return supplier.get(Long.MAX_VALUE);
}

/**
* Check if weight object can be cached
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class HybridDisiWrapper extends DisiWrapper {
private final int subQueryIndex;

public HybridDisiWrapper(Scorer scorer, int subQueryIndex) {
super(scorer);
super(scorer, false);
this.subQueryIndex = subQueryIndex;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ private HybridQueryScorer getHybridQueryScorer(final Scorable scorer) throws IOE
return (HybridQueryScorer) scorer;
}
for (Scorable.ChildScorable childScorable : scorer.getChildren()) {
HybridQueryScorer hybridQueryScorer = getHybridQueryScorer(childScorable.child);
HybridQueryScorer hybridQueryScorer = getHybridQueryScorer(childScorable.child());
if (Objects.nonNull(hybridQueryScorer)) {
log.debug(
String.format(
Locale.ROOT,
"found hybrid query scorer, it's child of scorer %s",
childScorable.child.getClass().getSimpleName()
childScorable.child().getClass().getSimpleName()
)
);
return hybridQueryScorer;
Expand Down Expand Up @@ -289,7 +289,7 @@ private void initializeLeafFieldComparators(LeafReaderContext context, int subQu
private void initializeComparators(LeafReaderContext context, int subQueryNumber) throws IOException {
// as all segments are sorted in the same way, enough to check only the 1st segment for indexSort
if (searchSortPartOfIndexSort == null) {
Sort indexSort = context.reader().getMetaData().getSort();
Sort indexSort = context.reader().getMetaData().sort();
searchSortPartOfIndexSort = canEarlyTerminate(sort, indexSort);
if (searchSortPartOfIndexSort) {
firstComparator.disableSkipping();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ private HybridQueryScorer getHybridQueryScorer(final Scorable scorer) throws IOE
return (HybridQueryScorer) scorer;
}
for (Scorable.ChildScorable childScorable : scorer.getChildren()) {
HybridQueryScorer hybridQueryScorer = getHybridQueryScorer(childScorable.child);
HybridQueryScorer hybridQueryScorer = getHybridQueryScorer(childScorable.child());
if (Objects.nonNull(hybridQueryScorer)) {
log.debug(
String.format(
Locale.ROOT,
"found hybrid query scorer, it's child of scorer %s",
childScorable.child.getClass().getSimpleName()
childScorable.child().getClass().getSimpleName()
)
);
return hybridQueryScorer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ private void reduceCollectorResults(
}
// in this case top docs are already present in result, and we need to merge next result object with what we have.
// if collector doesn't have any hits we can just skip it and save some cycles by not doing merge
if (topDocsAndMaxScore.topDocs.totalHits.value == 0) {
if (topDocsAndMaxScore.topDocs.totalHits.value() == 0) {
return;
}
// we need to do actual merge because query result and current collector both have some score hits
Expand Down Expand Up @@ -509,7 +509,7 @@ private static HybridQuery unwrapHybridQuery(final SearchContext searchContext)
// In case of nested fields and alias filter, hybrid query is wrapped under bool query and lies in the first clause.
if (isHybridQueryWrappedInBooleanQuery(searchContext, searchContext.query())) {
BooleanQuery booleanQuery = (BooleanQuery) query;
hybridQuery = (HybridQuery) booleanQuery.clauses().get(0).getQuery();
hybridQuery = (HybridQuery) booleanQuery.clauses().get(0).query();
} else {
hybridQuery = (HybridQuery) query;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ private QueryPhaseSearcher getQueryPhaseSearcher(final SearchContext searchConte
protected Query extractHybridQuery(final SearchContext searchContext, final Query query) {
if (isHybridQueryWrappedInBooleanQuery(searchContext, query)) {
List<BooleanClause> booleanClauses = ((BooleanQuery) query).clauses();
if (!(booleanClauses.get(0).getQuery() instanceof HybridQuery)) {
if (!(booleanClauses.get(0).query() instanceof HybridQuery)) {
throw new IllegalStateException("cannot process hybrid query due to incorrect structure of top level query");
}
HybridQuery hybridQuery = (HybridQuery) booleanClauses.stream().findFirst().get().getQuery();
HybridQuery hybridQuery = (HybridQuery) booleanClauses.stream().findFirst().get().query();
List<Query> filterQueries = booleanClauses.stream()
.filter(clause -> BooleanClause.Occur.FILTER == clause.getOccur())
.map(BooleanClause::getQuery)
.filter(clause -> BooleanClause.Occur.FILTER == clause.occur())
.map(BooleanClause::query)
.collect(Collectors.toList());
HybridQuery hybridQueryWithFilter = new HybridQuery(hybridQuery.getSubQueries(), filterQueries, hybridQuery.getQueryContext());
return hybridQueryWithFilter;
Expand Down Expand Up @@ -113,7 +113,7 @@ private void validateQuery(final SearchContext searchContext, final Query query)
if (query instanceof BooleanQuery) {
List<BooleanClause> booleanClauses = ((BooleanQuery) query).clauses();
for (BooleanClause booleanClause : booleanClauses) {
validateNestedBooleanQuery(booleanClause.getQuery(), getMaxDepthLimit(searchContext));
validateNestedBooleanQuery(booleanClause.query(), getMaxDepthLimit(searchContext));
}
} else if (query instanceof DisjunctionMaxQuery) {
for (Query disjunct : (DisjunctionMaxQuery) query) {
Expand All @@ -135,7 +135,7 @@ private void validateNestedBooleanQuery(final Query query, final int level) {
}
if (query instanceof BooleanQuery) {
for (BooleanClause booleanClause : ((BooleanQuery) query).clauses()) {
validateNestedBooleanQuery(booleanClause.getQuery(), level - 1);
validateNestedBooleanQuery(booleanClause.query(), level - 1);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public TopDocsAndMaxScore merge(final TopDocsAndMaxScore source, final TopDocsAn
private static boolean isEmpty(final TopDocsAndMaxScore topDocsAndMaxScore) {
if (Objects.isNull(topDocsAndMaxScore)
|| Objects.isNull(topDocsAndMaxScore.topDocs)
|| topDocsAndMaxScore.topDocs.totalHits.value == 0) {
|| topDocsAndMaxScore.topDocs.totalHits.value() == 0) {
return true;
}
return false;
Expand All @@ -89,11 +89,11 @@ private static boolean isEmpty(final TopDocsAndMaxScore topDocsAndMaxScore) {
private TotalHits getMergedTotalHits(final TopDocsAndMaxScore source, final TopDocsAndMaxScore newTopDocs) {
// merged value is a lower bound - if both are equal_to than merged will also be equal_to,
// otherwise assign greater_than_or_equal
TotalHits.Relation mergedHitsRelation = source.topDocs.totalHits.relation == TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO
|| newTopDocs.topDocs.totalHits.relation == TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO
TotalHits.Relation mergedHitsRelation = source.topDocs.totalHits.relation() == TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO
|| newTopDocs.topDocs.totalHits.relation() == TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO
? TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO
: TotalHits.Relation.EQUAL_TO;
return new TotalHits(source.topDocs.totalHits.value + newTopDocs.topDocs.totalHits.value, mergedHitsRelation);
return new TotalHits(source.topDocs.totalHits.value() + newTopDocs.topDocs.totalHits.value(), mergedHitsRelation);
}

private TopDocs getTopDocs(ScoreDoc[] mergedScoreDocs, TotalHits mergedTotalHits) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static boolean hasNestedFieldOrNestedDocs(final Query query, final Searc

private static boolean isWrappedHybridQuery(final Query query) {
return query instanceof BooleanQuery
&& ((BooleanQuery) query).clauses().stream().anyMatch(clauseQuery -> clauseQuery.getQuery() instanceof HybridQuery);
&& ((BooleanQuery) query).clauses().stream().anyMatch(clauseQuery -> clauseQuery.query() instanceof HybridQuery);
}

private static boolean hasAliasFilter(final Query query, final SearchContext searchContext) {
Expand Down

0 comments on commit cfde072

Please sign in to comment.