Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Change implementation for `percentiles` aggregation for latency improvement ([#19648](https://github.com/opensearch-project/OpenSearch/pull/19648))
- Refactor the ThreadPoolStats.Stats class to use the Builder pattern instead of constructors ([#19306](https://github.com/opensearch-project/OpenSearch/pull/19306))
- Refactor the IndexingStats.Stats class to use the Builder pattern instead of constructors ([#19306](https://github.com/opensearch-project/OpenSearch/pull/19306))
- Replace explicit type conversion with instanceof pattern variable in org.opensearch.search package ([#19714](https://github.com/opensearch-project/OpenSearch/pull/19714))

### Fixed
- Fix Allocation and Rebalance Constraints of WeightFunction are incorrectly reset ([#19012](https://github.com/opensearch-project/OpenSearch/pull/19012))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ public BytesRef parseBytesRef(String value) {
};

static DocValueFormat withNanosecondResolution(final DocValueFormat format) {
if (format instanceof DateTime) {
DateTime dateTime = (DateTime) format;
if (format instanceof DateTime dateTime) {
return new DateTime(dateTime.formatter, dateTime.timeZone, DateFieldMapper.Resolution.NANOSECONDS);
} else {
throw new IllegalArgumentException("trying to convert a known date time formatter to a nanosecond one, wrong field used?");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1244,8 +1244,8 @@ protected int pick(SortedDocValues values, DocIdSetIterator docItr, int startDoc
*/
public NumericDocValues select(final SortedNumericUnsignedLongValues values) {
SortedNumericDocValues sortedNumericDocValues = null;
if (values instanceof LongToSortedNumericUnsignedLongValues) {
sortedNumericDocValues = ((LongToSortedNumericUnsignedLongValues) values).getNumericUnsignedLongValues();
if (values instanceof LongToSortedNumericUnsignedLongValues longValues) {
sortedNumericDocValues = longValues.getNumericUnsignedLongValues();
}

final NumericDocValues singleton = DocValues.unwrapSingleton(sortedNumericDocValues);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1213,8 +1213,8 @@ public void updatePitIdAndKeepAlive(UpdatePitContextRequest request, ActionListe
*/
public PitReaderContext getPitReaderContext(ShardSearchContextId id) {
ReaderContext context = activeReaders.get(id.getId());
if (context instanceof PitReaderContext) {
return (PitReaderContext) context;
if (context instanceof PitReaderContext pitReaderContext) {
return pitReaderContext;
}
return null;
}
Expand All @@ -1225,8 +1225,7 @@ public PitReaderContext getPitReaderContext(ShardSearchContextId id) {
public List<ListPitInfo> getAllPITReaderContexts() {
final List<ListPitInfo> pitContextsInfo = new ArrayList<>();
for (ReaderContext ctx : activeReaders.values()) {
if (ctx instanceof PitReaderContext) {
final PitReaderContext context = (PitReaderContext) ctx;
if (ctx instanceof PitReaderContext context) {
ListPitInfo pitInfo = new ListPitInfo(context.getPitId(), context.getCreationTime(), context.getKeepAlive());
pitContextsInfo.add(pitInfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ public SearchSortValues(Object[] rawSortValues, DocValueFormat[] sortValueFormat
this.formattedSortValues = Arrays.copyOf(rawSortValues, rawSortValues.length);
for (int i = 0; i < rawSortValues.length; ++i) {
Object sortValue = rawSortValues[i];
if (sortValue instanceof BytesRef) {
this.formattedSortValues[i] = sortValueFormats[i].format((BytesRef) sortValue);
} else if ((sortValue instanceof Long) && (sortValueFormats[i] == DocValueFormat.UNSIGNED_LONG_SHIFTED)) {
this.formattedSortValues[i] = sortValueFormats[i].format((Long) sortValue);
} else if ((sortValue instanceof Long) && (sortValueFormats[i] == DocValueFormat.UNSIGNED_LONG)) {
this.formattedSortValues[i] = sortValueFormats[i].format((Long) sortValue);
if (sortValue instanceof BytesRef bytesRef) {
this.formattedSortValues[i] = sortValueFormats[i].format(bytesRef);
} else if ((sortValue instanceof Long longValue) && (sortValueFormats[i] == DocValueFormat.UNSIGNED_LONG_SHIFTED)) {
this.formattedSortValues[i] = sortValueFormats[i].format(longValue);
} else if ((sortValue instanceof Long longValue) && (sortValueFormats[i] == DocValueFormat.UNSIGNED_LONG)) {
this.formattedSortValues[i] = sortValueFormats[i].format(longValue);
} else {
this.formattedSortValues[i] = sortValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ private static AggregatorFactories.Builder parseAggregators(XContentParser parse
aggBuilder.subAggregations(subFactories);
}

if (aggBuilder instanceof AggregationBuilder) {
factories.addAggregator((AggregationBuilder) aggBuilder);
if (aggBuilder instanceof AggregationBuilder aggregationBuilder) {
factories.addAggregator(aggregationBuilder);
} else {
factories.addPipelineAggregator((PipelineAggregationBuilder) aggBuilder);
}
Expand Down Expand Up @@ -388,8 +388,8 @@ public boolean mustVisitAllDocs() {
for (AggregationBuilder builder : aggregationBuilders) {
if (builder instanceof GlobalAggregationBuilder) {
return true;
} else if (builder instanceof TermsAggregationBuilder) {
if (((TermsAggregationBuilder) builder).minDocCount() == 0) {
} else if (builder instanceof TermsAggregationBuilder termsAggregationBuilder) {
if (termsAggregationBuilder.minDocCount() == 0) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@ public void processPostCollection(Collector collectorTree) throws IOException {
collectors.offer(collectorTree);
while (!collectors.isEmpty()) {
Collector currentCollector = collectors.poll();
if (currentCollector instanceof InternalProfileCollector) {
collectors.offer(((InternalProfileCollector) currentCollector).getCollector());
} else if (currentCollector instanceof MinimumScoreCollector) {
collectors.offer(((MinimumScoreCollector) currentCollector).getCollector());
} else if (currentCollector instanceof MultiCollector) {
for (Collector innerCollector : ((MultiCollector) currentCollector).getCollectors()) {
if (currentCollector instanceof InternalProfileCollector internalProfileCollector) {
collectors.offer(internalProfileCollector.getCollector());
} else if (currentCollector instanceof MinimumScoreCollector minimumScoreCollector) {
collectors.offer(minimumScoreCollector.getCollector());
} else if (currentCollector instanceof MultiCollector multiCollector) {
for (Collector innerCollector : multiCollector.getCollectors()) {
collectors.offer(innerCollector);
}
} else if (currentCollector instanceof BucketCollector) {
} else if (currentCollector instanceof BucketCollector bucketCollector) {
// Perform build aggregation during post collection
if (currentCollector instanceof Aggregator) {
if (currentCollector instanceof Aggregator aggregator) {
// Do not perform postCollection for MultiBucketCollector as we are unwrapping that below
((BucketCollector) currentCollector).postCollection();
((Aggregator) currentCollector).buildTopLevel();
} else if (currentCollector instanceof MultiBucketCollector) {
for (Collector innerCollector : ((MultiBucketCollector) currentCollector).getCollectors()) {
bucketCollector.postCollection();
aggregator.buildTopLevel();
} else if (currentCollector instanceof MultiBucketCollector multiBucketCollector) {
for (Collector innerCollector : multiBucketCollector.getCollectors()) {
collectors.offer(innerCollector);
}
}
Expand All @@ -97,23 +97,23 @@ public List<InternalAggregation> buildAggBatch(Collector collectorTree) throws I
collectors.offer(collectorTree);
while (!collectors.isEmpty()) {
Collector currentCollector = collectors.poll();
if (currentCollector instanceof InternalProfileCollector) {
collectors.offer(((InternalProfileCollector) currentCollector).getCollector());
} else if (currentCollector instanceof MinimumScoreCollector) {
collectors.offer(((MinimumScoreCollector) currentCollector).getCollector());
} else if (currentCollector instanceof MultiCollector) {
for (Collector innerCollector : ((MultiCollector) currentCollector).getCollectors()) {
if (currentCollector instanceof InternalProfileCollector internalProfileCollector) {
collectors.offer(internalProfileCollector.getCollector());
} else if (currentCollector instanceof MinimumScoreCollector minimumScoreCollector) {
collectors.offer(minimumScoreCollector.getCollector());
} else if (currentCollector instanceof MultiCollector multiCollector) {
for (Collector innerCollector : multiCollector.getCollectors()) {
collectors.offer(innerCollector);
}
} else if (currentCollector instanceof BucketCollector) {
} else if (currentCollector instanceof BucketCollector bucketCollector) {
// Perform build aggregation during post collection
if (currentCollector instanceof Aggregator) {
if (currentCollector instanceof Aggregator aggregator) {
// Call postCollection() before building to ensure collectors finalize their data
// This is critical for aggregators like CardinalityAggregator that defer processing until postCollect()
((BucketCollector) currentCollector).postCollection();
aggregations.add(((Aggregator) currentCollector).buildTopLevelBatch());
} else if (currentCollector instanceof MultiBucketCollector) {
for (Collector innerCollector : ((MultiBucketCollector) currentCollector).getCollectors()) {
bucketCollector.postCollection();
aggregations.add(aggregator.buildTopLevelBatch());
} else if (currentCollector instanceof MultiBucketCollector multiBucketCollector) {
for (Collector innerCollector : multiBucketCollector.getCollectors()) {
collectors.offer(innerCollector);
}
}
Expand All @@ -136,18 +136,16 @@ public List<Aggregator> toAggregators(Collection<Collector> collectors) {
final Deque<Collector> allCollectors = new LinkedList<>(collectors);
while (!allCollectors.isEmpty()) {
final Collector currentCollector = allCollectors.pop();
if (currentCollector instanceof Aggregator) {
aggregators.add((Aggregator) currentCollector);
} else if (currentCollector instanceof InternalProfileCollector) {
if (((InternalProfileCollector) currentCollector).getCollector() instanceof Aggregator) {
aggregators.add((Aggregator) ((InternalProfileCollector) currentCollector).getCollector());
} else if (((InternalProfileCollector) currentCollector).getCollector() instanceof MultiBucketCollector) {
allCollectors.addAll(
Arrays.asList(((MultiBucketCollector) ((InternalProfileCollector) currentCollector).getCollector()).getCollectors())
);
if (currentCollector instanceof Aggregator aggregator) {
aggregators.add(aggregator);
} else if (currentCollector instanceof InternalProfileCollector internalProfileCollector) {
if (internalProfileCollector.getCollector() instanceof Aggregator aggregator) {
aggregators.add(aggregator);
} else if (internalProfileCollector.getCollector() instanceof MultiBucketCollector multiBucketCollector) {
allCollectors.addAll(Arrays.asList(multiBucketCollector.getCollectors()));
}
} else if (currentCollector instanceof MultiBucketCollector) {
allCollectors.addAll(Arrays.asList(((MultiBucketCollector) currentCollector).getCollectors()));
} else if (currentCollector instanceof MultiBucketCollector multiBucketCollector) {
allCollectors.addAll(Arrays.asList(multiBucketCollector.getCollectors()));
}
}
return aggregators;
Expand All @@ -167,14 +165,14 @@ public List<InternalAggregation> toInternalAggregations(Collection<Collector> co
final Deque<Collector> allCollectors = new LinkedList<>(collectors);
while (!allCollectors.isEmpty()) {
Collector currentCollector = allCollectors.pop();
if (currentCollector instanceof InternalProfileCollector) {
currentCollector = ((InternalProfileCollector) currentCollector).getCollector();
if (currentCollector instanceof InternalProfileCollector internalProfileCollector) {
currentCollector = internalProfileCollector.getCollector();
}

if (currentCollector instanceof Aggregator) {
internalAggregations.add(((Aggregator) currentCollector).getPostCollectionAggregation());
} else if (currentCollector instanceof MultiBucketCollector) {
allCollectors.addAll(Arrays.asList(((MultiBucketCollector) currentCollector).getCollectors()));
if (currentCollector instanceof Aggregator aggregator) {
internalAggregations.add(aggregator.getPostCollectionAggregation());
} else if (currentCollector instanceof MultiBucketCollector multiBucketCollector) {
allCollectors.addAll(Arrays.asList(multiBucketCollector.getCollectors()));
}
}
return internalAggregations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,14 @@ public static int countInnerBucket(InternalBucket bucket) {
*/
public static int countInnerBucket(Aggregation agg) {
int size = 0;
if (agg instanceof MultiBucketsAggregation) {
MultiBucketsAggregation multi = (MultiBucketsAggregation) agg;
if (agg instanceof MultiBucketsAggregation multi) {
for (MultiBucketsAggregation.Bucket bucket : multi.getBuckets()) {
++size;
for (Aggregation bucketAgg : bucket.getAggregations().asList()) {
size += countInnerBucket(bucketAgg);
}
}
} else if (agg instanceof SingleBucketAggregation) {
SingleBucketAggregation single = (SingleBucketAggregation) agg;
} else if (agg instanceof SingleBucketAggregation single) {
for (Aggregation bucketAgg : single.getAggregations().asList()) {
size += countInnerBucket(bucketAgg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ private static Comparator<Bucket> comparingCounts() {
@SuppressWarnings("unchecked")
private static Comparator<Bucket> comparingKeys() {
return (b1, b2) -> {
if (b1 instanceof KeyComparable) {
return ((KeyComparable) b1).compareKey(b2);
if (b1 instanceof KeyComparable keyComparable) {
return keyComparable.compareKey(b2);
}
throw new IllegalStateException("Unexpected order bucket class [" + b1.getClass() + "]");
};
Expand Down Expand Up @@ -399,9 +399,9 @@ public static boolean isKeyDesc(BucketOrder order) {
private static boolean isOrder(BucketOrder order, BucketOrder expected) {
if (order == expected) {
return true;
} else if (order instanceof CompoundOrder) {
} else if (order instanceof CompoundOrder compoundOrder) {
// check if its a compound order with the first element that matches
List<BucketOrder> orders = ((CompoundOrder) order).orderElements;
List<BucketOrder> orders = compoundOrder.orderElements;
if (orders.size() >= 1) {
return isOrder(orders.get(0), expected);
}
Expand Down Expand Up @@ -472,12 +472,10 @@ public static BucketOrder readHistogramOrder(StreamInput in, boolean bwcOrderFla
*/
public static void writeOrder(BucketOrder order, StreamOutput out) throws IOException {
out.writeByte(order.id());
if (order instanceof Aggregation) {
Aggregation aggregationOrder = (Aggregation) order;
if (order instanceof Aggregation aggregationOrder) {
out.writeBoolean(aggregationOrder.order == SortOrder.ASC);
out.writeString(aggregationOrder.path().toString());
} else if (order instanceof CompoundOrder) {
CompoundOrder compoundOrder = (CompoundOrder) order;
} else if (order instanceof CompoundOrder compoundOrder) {
out.writeVInt(compoundOrder.orderElements.size());
for (BucketOrder innerOrder : compoundOrder.orderElements) {
innerOrder.writeTo(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public class LeafBucketCollectorBase extends LeafBucketCollector {
*/
public LeafBucketCollectorBase(LeafBucketCollector sub, Object values) {
this.sub = sub;
if (values instanceof ScorerAware) {
this.values = (ScorerAware) values;
if (values instanceof ScorerAware scorerAware) {
this.values = scorerAware;
} else {
this.values = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,12 @@ public void validateHasParent(String type, String name) {

@Override
public void validateParentAggSequentiallyOrdered(String type, String name) {
if (parent instanceof HistogramAggregationBuilder) {
HistogramAggregationBuilder histoParent = (HistogramAggregationBuilder) parent;
if (histoParent.minDocCount() != 0) {
if (parent instanceof HistogramAggregationBuilder histogramAggregationBuilder) {
if (histogramAggregationBuilder.minDocCount() != 0) {
addValidationError("parent histogram of " + type + " aggregation [" + name + "] must have min_doc_count of 0");
}
} else if (parent instanceof DateHistogramAggregationBuilder) {
DateHistogramAggregationBuilder histoParent = (DateHistogramAggregationBuilder) parent;
if (histoParent.minDocCount() != 0) {
} else if (parent instanceof DateHistogramAggregationBuilder dateHistogramAggregationBuilder) {
if (dateHistogramAggregationBuilder.minDocCount() != 0) {
addValidationError("parent histogram of " + type + " aggregation [" + name + "] must have min_doc_count of 0");
}
} else if (parent instanceof AutoDateHistogramAggregationBuilder) {
Expand Down
Loading
Loading