-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vamsi Manohar <[email protected]>
- Loading branch information
Showing
7 changed files
with
218 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
20 changes: 20 additions & 0 deletions
20
server/src/main/java/org/opensearch/search/externalengine/QueryEngine.java
This file contains 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,20 @@ | ||
/* | ||
* 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.search.externalengine; | ||
|
||
import org.opensearch.action.search.SearchRequest; | ||
import org.opensearch.action.search.SearchResponse; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.core.common.io.stream.NamedWriteable; | ||
import org.opensearch.core.xcontent.ToXContentObject; | ||
|
||
public abstract class QueryEngine implements NamedWriteable, ToXContentObject { | ||
public abstract void executeQuery(SearchRequest searchRequest, | ||
ActionListener<SearchResponse> actionListener); | ||
} |
25 changes: 25 additions & 0 deletions
25
server/src/main/java/org/opensearch/search/externalengine/QueryEngineParser.java
This file contains 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,25 @@ | ||
/* | ||
* 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.search.externalengine; | ||
|
||
import java.io.IOException; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
import org.opensearch.index.query.QueryBuilder; | ||
|
||
@FunctionalInterface | ||
public interface QueryEngineParser<T extends QueryEngine> { | ||
|
||
/** | ||
* Creates a new {@link QueryBuilder} from the query held by the | ||
* {@link XContentParser}. The state on the parser contained in this context | ||
* will be changed as a side effect of this method call | ||
*/ | ||
T fromXContent(XContentParser parser) throws IOException; | ||
|
||
} |
84 changes: 84 additions & 0 deletions
84
server/src/main/java/org/opensearch/search/externalengine/SQLQueryEngine.java
This file contains 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,84 @@ | ||
/* | ||
* 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.search.externalengine; | ||
|
||
import static org.opensearch.repositories.fs.ReloadableFsRepository.randomIntBetween; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import org.opensearch.action.search.SearchRequest; | ||
import org.opensearch.action.search.SearchResponse; | ||
import org.opensearch.action.search.ShardSearchFailure; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
import org.opensearch.search.internal.InternalSearchResponse; | ||
|
||
public class SQLQueryEngine extends QueryEngine { | ||
|
||
public static final String NAME = "sql"; | ||
|
||
public SQLQueryEngine() { | ||
|
||
} | ||
public SQLQueryEngine(StreamInput in) { | ||
} | ||
@Override | ||
public String getWriteableName() { | ||
return "sql"; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
} | ||
|
||
|
||
@Override | ||
public void executeQuery(SearchRequest searchRequest, | ||
ActionListener<SearchResponse> actionListener) { | ||
// Creating a minimal response is OK, because SearchResponse self | ||
// is tested elsewhere. | ||
long tookInMillis = ThreadLocalRandom.current().nextLong(0L, Long.MAX_VALUE); | ||
int totalShards = randomIntBetween(1, Integer.MAX_VALUE); | ||
int successfulShards = randomIntBetween(0, totalShards); | ||
int skippedShards = totalShards - successfulShards; | ||
InternalSearchResponse internalSearchResponse = InternalSearchResponse.empty(); | ||
int totalClusters = randomIntBetween(0, 10); | ||
int successfulClusters = randomIntBetween(0, totalClusters); | ||
int skippedClusters = totalClusters - successfulClusters; | ||
SearchResponse.Clusters clusters = new SearchResponse.Clusters(totalClusters, successfulClusters, skippedClusters); | ||
SearchResponse searchResponse = new SearchResponse( | ||
internalSearchResponse, | ||
null, | ||
totalShards, | ||
successfulShards, | ||
skippedShards, | ||
tookInMillis, | ||
ShardSearchFailure.EMPTY_ARRAY, | ||
clusters | ||
); | ||
actionListener.onResponse(searchResponse); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return null; | ||
} | ||
|
||
public static QueryEngine fromXContent(XContentParser parser) throws IOException { | ||
XContentParser.Token token; | ||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { | ||
token = parser.nextToken(); | ||
} | ||
return new SQLQueryEngine(); | ||
} | ||
|
||
} |