-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Introduce Instructions for the Backend to use during execution #21479
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
Merged
mch2
merged 7 commits into
opensearch-project:main
from
expani:data_node_exec_with_instructions
May 6, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
43c6deb
Backend Execution Metadata Framework
expani fd36583
PR Comments
expani 91b0f59
Spotless and test fixes
expani e9c4b1e
Fixed tests and compilation issues
expani d740ed4
Spotless
expani 39b8408
Renamed things and fixed some tests
expani 25543f8
Fixed more conflicts with streaming PR
expani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...alytics-framework/src/main/java/org/opensearch/analytics/spi/BackendExecutionContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.analytics.spi; | ||
|
|
||
| /** | ||
| * Marker interface for backend-specific execution context that flows between | ||
| * successive instruction handler calls. The first handler in the chain receives | ||
| * {@code null} and bootstraps the context; subsequent handlers receive and build | ||
| * upon the previous handler's output. | ||
| * | ||
| * <p>Each backend defines its own concrete implementation (e.g., | ||
| * {@code DataFusionSessionState} holding a native SessionContext handle). | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public interface BackendExecutionContext {} |
22 changes: 22 additions & 0 deletions
22
...analytics-framework/src/main/java/org/opensearch/analytics/spi/BackendExecutionState.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.analytics.spi; | ||
|
|
||
| /** | ||
| * Marker interface for backend-specific execution state that flows between | ||
| * successive instruction handler calls. The first handler in the chain receives | ||
| * {@code null} and bootstraps the state; subsequent handlers receive and build | ||
| * upon the previous handler's output. | ||
| * | ||
| * <p>Each backend defines its own concrete implementation (e.g., | ||
| * {@code DataFusionSessionState} holding a native SessionContext handle). | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public interface BackendExecutionState {} | ||
21 changes: 21 additions & 0 deletions
21
...nalytics-framework/src/main/java/org/opensearch/analytics/spi/CommonExecutionContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.analytics.spi; | ||
|
|
||
| /** | ||
| * Marker interface for execution contexts provided by Core to instruction handlers. | ||
| * Concrete implementations carry the information relevant to their execution path: | ||
| * <ul> | ||
| * <li>{@code ShardScanExecutionContext} — shard fragment execution (reader, task, tableName)</li> | ||
| * <li>{@code ExchangeSinkContext} — coordinator reduce execution (planBytes, allocator, schema)</li> | ||
| * </ul> | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public interface CommonExecutionContext {} |
60 changes: 60 additions & 0 deletions
60
...s/analytics-framework/src/main/java/org/opensearch/analytics/spi/DelegatedExpression.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.analytics.spi; | ||
|
|
||
| import org.opensearch.core.common.io.stream.StreamInput; | ||
| import org.opensearch.core.common.io.stream.StreamOutput; | ||
| import org.opensearch.core.common.io.stream.Writeable; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * A single delegated predicate — carries the annotation ID, the accepting backend, | ||
| * and the serialized bytes produced by the accepting backend's | ||
| * {@link DelegatedPredicateSerializer} or anything similar. | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public class DelegatedExpression implements Writeable { | ||
|
|
||
| private final int annotationId; | ||
| private final String acceptingBackendId; | ||
| private final byte[] expressionBytes; | ||
|
|
||
| public DelegatedExpression(int annotationId, String acceptingBackendId, byte[] expressionBytes) { | ||
| this.annotationId = annotationId; | ||
| this.acceptingBackendId = acceptingBackendId; | ||
| this.expressionBytes = expressionBytes; | ||
| } | ||
|
|
||
| public DelegatedExpression(StreamInput in) throws IOException { | ||
| this.annotationId = in.readInt(); | ||
| this.acceptingBackendId = in.readString(); | ||
| this.expressionBytes = in.readByteArray(); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeInt(annotationId); | ||
| out.writeString(acceptingBackendId); | ||
| out.writeByteArray(expressionBytes); | ||
| } | ||
|
|
||
| public int getAnnotationId() { | ||
| return annotationId; | ||
| } | ||
|
|
||
| public String getAcceptingBackendId() { | ||
| return acceptingBackendId; | ||
| } | ||
|
|
||
| public byte[] getExpressionBytes() { | ||
| return expressionBytes; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...framework/src/main/java/org/opensearch/analytics/spi/FilterDelegationInstructionNode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.analytics.spi; | ||
|
|
||
| import org.opensearch.core.common.io.stream.StreamInput; | ||
| import org.opensearch.core.common.io.stream.StreamOutput; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Instruction node for filter delegation to an index backend. | ||
| * Carries the tree shape, predicate count, and serialized delegated queries. | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public class FilterDelegationInstructionNode implements InstructionNode { | ||
|
|
||
| private final FilterTreeShape treeShape; | ||
| private final int delegatedPredicateCount; | ||
| private final List<DelegatedExpression> delegatedQueries; | ||
|
|
||
| public FilterDelegationInstructionNode( | ||
| FilterTreeShape treeShape, | ||
| int delegatedPredicateCount, | ||
| List<DelegatedExpression> delegatedQueries | ||
| ) { | ||
| this.treeShape = treeShape; | ||
| this.delegatedPredicateCount = delegatedPredicateCount; | ||
| this.delegatedQueries = delegatedQueries; | ||
| } | ||
|
|
||
| public FilterDelegationInstructionNode(StreamInput in) throws IOException { | ||
| this.treeShape = in.readEnum(FilterTreeShape.class); | ||
| this.delegatedPredicateCount = in.readInt(); | ||
| this.delegatedQueries = in.readList(DelegatedExpression::new); | ||
| } | ||
|
|
||
| @Override | ||
| public InstructionType type() { | ||
| return InstructionType.SETUP_FILTER_DELEGATION_FOR_INDEX; | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeEnum(treeShape); | ||
| out.writeInt(delegatedPredicateCount); | ||
| out.writeCollection(delegatedQueries); | ||
| } | ||
|
|
||
| public FilterTreeShape getTreeShape() { | ||
| return treeShape; | ||
| } | ||
|
|
||
| public int getDelegatedPredicateCount() { | ||
| return delegatedPredicateCount; | ||
| } | ||
|
|
||
| public List<DelegatedExpression> getDelegatedQueries() { | ||
| return delegatedQueries; | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
.../libs/analytics-framework/src/main/java/org/opensearch/analytics/spi/FilterTreeShape.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.analytics.spi; | ||
|
|
||
| /** | ||
| * Backend-agnostic description of the boolean tree shape when filter delegation is active. | ||
| * Provided by the planner so backends can choose their execution strategy without | ||
| * re-inspecting the Substrait plan. | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public enum FilterTreeShape { | ||
|
expani marked this conversation as resolved.
|
||
| /** No delegation — all predicates handled natively by the driving backend. */ | ||
| NO_DELEGATION, | ||
| /** | ||
| * All predicates (delegated + native) are under a single AND — no interleaving | ||
| * under OR/NOT. Backend can handle delegated bitsets and native predicates independently. | ||
| */ | ||
| CONJUNCTIVE, | ||
| /** | ||
| * Delegated and native predicates are interleaved under OR/NOT — the boolean tree | ||
| * mixes predicates from different backends under non-AND operators. Backend needs a | ||
| * tree evaluator to combine bitsets from both backends per the boolean structure. | ||
| */ | ||
| INTERLEAVED_BOOLEAN_EXPRESSION | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
...s-framework/src/main/java/org/opensearch/analytics/spi/FinalAggregateInstructionNode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.analytics.spi; | ||
|
|
||
| import org.opensearch.core.common.io.stream.StreamInput; | ||
| import org.opensearch.core.common.io.stream.StreamOutput; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Instruction node for final aggregate in coordinator reduce — ExchangeSink path, | ||
| * remove partial agg, preserve final-only for the driving backend's reduce execution. | ||
| * | ||
| * <p>TODO: add backend-specific config fields as final aggregate implementation is built out. | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public class FinalAggregateInstructionNode implements InstructionNode { | ||
|
sandeshkr419 marked this conversation as resolved.
|
||
|
|
||
| public FinalAggregateInstructionNode() {} | ||
|
|
||
| public FinalAggregateInstructionNode(StreamInput in) throws IOException { | ||
| // TODO: read config fields when added | ||
| } | ||
|
|
||
| @Override | ||
| public InstructionType type() { | ||
| return InstructionType.SETUP_FINAL_AGGREGATE; | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| // TODO: write config fields when added | ||
| } | ||
| } | ||
31 changes: 31 additions & 0 deletions
31
...tics-framework/src/main/java/org/opensearch/analytics/spi/FragmentInstructionHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.analytics.spi; | ||
|
|
||
| /** | ||
| * Applies an {@link InstructionNode} to the execution context at the data node. | ||
| * Each handler is created per-execution by the backend's | ||
| * {@link FragmentInstructionHandlerFactory#createHandler(InstructionNode)}. | ||
| * | ||
| * @param <N> the concrete instruction node type this handler processes | ||
| * @opensearch.internal | ||
| */ | ||
| public interface FragmentInstructionHandler<N extends InstructionNode> { | ||
|
|
||
| /** | ||
| * Applies the instruction, reading from Core's context and building upon the | ||
| * backend's accumulated execution context from previous handlers. | ||
| * | ||
| * @param node the instruction node | ||
| * @param commonContext Core-provided context (shard info or reduce info) | ||
| * @param backendContext backend state from previous handler, or {@code null} for the first handler | ||
| * @return updated backend execution context for the next handler or final consumer | ||
| */ | ||
| BackendExecutionContext apply(N node, CommonExecutionContext commonContext, BackendExecutionContext backendContext); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.