forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request opensearch-project#1078 from penghuo/feature/maxim…
…us/2.x Merge feature/maximus-m1 to 2.x
- Loading branch information
Showing
114 changed files
with
4,265 additions
and
1,081 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
26 changes: 26 additions & 0 deletions
26
core/src/main/java/org/opensearch/sql/ast/statement/Explain.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,26 @@ | ||
/* | ||
* 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.sql.ast.statement; | ||
|
||
import lombok.Data; | ||
import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
|
||
/** | ||
* Explain Statement. | ||
*/ | ||
@Data | ||
public class Explain extends Statement { | ||
|
||
private final Statement statement; | ||
|
||
@Override | ||
public <R, C> R accept(AbstractNodeVisitor<R, C> visitor, C context) { | ||
return visitor.visitExplain(this, context); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
core/src/main/java/org/opensearch/sql/ast/statement/Query.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,35 @@ | ||
/* | ||
* 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.sql.ast.statement; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
import org.opensearch.sql.ast.tree.UnresolvedPlan; | ||
|
||
/** | ||
* Query Statement. | ||
*/ | ||
@Getter | ||
@Setter | ||
@ToString | ||
@EqualsAndHashCode(callSuper = false) | ||
@RequiredArgsConstructor | ||
public class Query extends Statement { | ||
|
||
private final UnresolvedPlan plan; | ||
|
||
@Override | ||
public <R, C> R accept(AbstractNodeVisitor<R, C> visitor, C context) { | ||
return visitor.visitQuery(this, context); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
core/src/main/java/org/opensearch/sql/ast/statement/Statement.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,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.sql.ast.statement; | ||
|
||
import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
import org.opensearch.sql.ast.Node; | ||
|
||
/** | ||
* Statement is the high interface of core engine. | ||
*/ | ||
public abstract class Statement extends Node { | ||
@Override | ||
public <R, C> R accept(AbstractNodeVisitor<R, C> visitor, C context) { | ||
return visitor.visitStatement(this, context); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
core/src/main/java/org/opensearch/sql/executor/DefaultQueryManager.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,24 @@ | ||
/* | ||
* 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.sql.executor; | ||
|
||
import org.opensearch.sql.executor.execution.AbstractPlan; | ||
|
||
/** | ||
* Default QueryManager implementation which execute {@link AbstractPlan} on caller thread. | ||
*/ | ||
public class DefaultQueryManager implements QueryManager { | ||
|
||
@Override | ||
public QueryId submit(AbstractPlan queryExecution) { | ||
queryExecution.execute(); | ||
|
||
return queryExecution.getQueryId(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
core/src/main/java/org/opensearch/sql/executor/QueryId.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,36 @@ | ||
/* | ||
* 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.sql.executor; | ||
|
||
import lombok.Getter; | ||
import org.apache.commons.lang3.RandomStringUtils; | ||
import org.opensearch.sql.executor.execution.AbstractPlan; | ||
|
||
/** | ||
* Query id of {@link AbstractPlan}. | ||
*/ | ||
public class QueryId { | ||
/** | ||
* Query id. | ||
*/ | ||
@Getter | ||
private final String queryId; | ||
|
||
/** | ||
* Generate {@link QueryId}. | ||
* @return {@link QueryId}. | ||
*/ | ||
public static QueryId queryId() { | ||
return new QueryId(RandomStringUtils.random(10, true, true)); | ||
} | ||
|
||
private QueryId(String queryId) { | ||
this.queryId = queryId; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
core/src/main/java/org/opensearch/sql/executor/QueryManager.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.sql.executor; | ||
|
||
import org.opensearch.sql.executor.execution.AbstractPlan; | ||
|
||
/** | ||
* QueryManager is the high-level interface of core engine. | ||
* Frontend submit {@link AbstractPlan} to QueryManager. | ||
*/ | ||
public interface QueryManager { | ||
|
||
/** | ||
* Submit {@link AbstractPlan}. | ||
* @param queryPlan {@link AbstractPlan}. | ||
* @return {@link QueryId}. | ||
*/ | ||
QueryId submit(AbstractPlan queryPlan); | ||
} |
97 changes: 97 additions & 0 deletions
97
core/src/main/java/org/opensearch/sql/executor/QueryService.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,97 @@ | ||
/* | ||
* 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.sql.executor; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.opensearch.sql.analysis.AnalysisContext; | ||
import org.opensearch.sql.analysis.Analyzer; | ||
import org.opensearch.sql.ast.tree.UnresolvedPlan; | ||
import org.opensearch.sql.common.response.ResponseListener; | ||
import org.opensearch.sql.planner.PlanContext; | ||
import org.opensearch.sql.planner.Planner; | ||
import org.opensearch.sql.planner.logical.LogicalPlan; | ||
import org.opensearch.sql.planner.physical.PhysicalPlan; | ||
|
||
/** | ||
* The low level interface of core engine. | ||
*/ | ||
@RequiredArgsConstructor | ||
public class QueryService { | ||
|
||
private final Analyzer analyzer; | ||
|
||
private final ExecutionEngine executionEngine; | ||
|
||
private final Planner planner; | ||
|
||
/** | ||
* Execute the {@link UnresolvedPlan}, using {@link ResponseListener} to get response. | ||
* Todo. deprecated this interface after finalize {@link PlanContext}. | ||
* | ||
* @param plan {@link UnresolvedPlan} | ||
* @param listener {@link ResponseListener} | ||
*/ | ||
public void execute(UnresolvedPlan plan, | ||
ResponseListener<ExecutionEngine.QueryResponse> listener) { | ||
try { | ||
executePlan(analyze(plan), PlanContext.emptyPlanContext(), listener); | ||
} catch (Exception e) { | ||
listener.onFailure(e); | ||
} | ||
} | ||
|
||
/** | ||
* Execute the {@link UnresolvedPlan}, with {@link PlanContext} and using {@link ResponseListener} | ||
* to get response. | ||
* Todo. Pass split from PlanContext to ExecutionEngine in following PR. | ||
* | ||
* @param plan {@link LogicalPlan} | ||
* @param planContext {@link PlanContext} | ||
* @param listener {@link ResponseListener} | ||
*/ | ||
public void executePlan(LogicalPlan plan, | ||
PlanContext planContext, | ||
ResponseListener<ExecutionEngine.QueryResponse> listener) { | ||
try { | ||
executionEngine.execute(plan(plan), listener); | ||
} catch (Exception e) { | ||
listener.onFailure(e); | ||
} | ||
} | ||
|
||
/** | ||
* Explain the query in {@link UnresolvedPlan} using {@link ResponseListener} to | ||
* get and format explain response. | ||
* | ||
* @param plan {@link UnresolvedPlan} | ||
* @param listener {@link ResponseListener} for explain response | ||
*/ | ||
public void explain(UnresolvedPlan plan, | ||
ResponseListener<ExecutionEngine.ExplainResponse> listener) { | ||
try { | ||
executionEngine.explain(plan(analyze(plan)), listener); | ||
} catch (Exception e) { | ||
listener.onFailure(e); | ||
} | ||
} | ||
|
||
/** | ||
* Analyze {@link UnresolvedPlan}. | ||
*/ | ||
public LogicalPlan analyze(UnresolvedPlan plan) { | ||
return analyzer.analyze(plan, new AnalysisContext()); | ||
} | ||
|
||
/** | ||
* Translate {@link LogicalPlan} to {@link PhysicalPlan}. | ||
*/ | ||
public PhysicalPlan plan(LogicalPlan plan) { | ||
return planner.plan(plan); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
core/src/main/java/org/opensearch/sql/executor/execution/AbstractPlan.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,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.sql.executor.execution; | ||
|
||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.opensearch.sql.common.response.ResponseListener; | ||
import org.opensearch.sql.executor.ExecutionEngine; | ||
import org.opensearch.sql.executor.QueryId; | ||
|
||
/** | ||
* AbstractPlan represent the execution entity of the Statement. | ||
*/ | ||
@RequiredArgsConstructor | ||
public abstract class AbstractPlan { | ||
|
||
/** | ||
* Uniq query id. | ||
*/ | ||
@Getter | ||
private final QueryId queryId; | ||
|
||
/** | ||
* Start query execution. | ||
*/ | ||
public abstract void execute(); | ||
|
||
/** | ||
* Explain query execution. | ||
* | ||
* @param listener query explain response listener. | ||
*/ | ||
public abstract void explain(ResponseListener<ExecutionEngine.ExplainResponse> listener); | ||
} |
44 changes: 44 additions & 0 deletions
44
core/src/main/java/org/opensearch/sql/executor/execution/ExplainPlan.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,44 @@ | ||
/* | ||
* 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.sql.executor.execution; | ||
|
||
import org.opensearch.sql.common.response.ResponseListener; | ||
import org.opensearch.sql.executor.ExecutionEngine; | ||
import org.opensearch.sql.executor.QueryId; | ||
|
||
/** | ||
* Explain plan. | ||
*/ | ||
public class ExplainPlan extends AbstractPlan { | ||
|
||
private final AbstractPlan plan; | ||
|
||
private final ResponseListener<ExecutionEngine.ExplainResponse> explainListener; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public ExplainPlan(QueryId queryId, | ||
AbstractPlan plan, | ||
ResponseListener<ExecutionEngine.ExplainResponse> explainListener) { | ||
super(queryId); | ||
this.plan = plan; | ||
this.explainListener = explainListener; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
plan.explain(explainListener); | ||
} | ||
|
||
@Override | ||
public void explain(ResponseListener<ExecutionEngine.ExplainResponse> listener) { | ||
throw new UnsupportedOperationException("explain query can not been explained."); | ||
} | ||
} |
Oops, something went wrong.