-
Notifications
You must be signed in to change notification settings - Fork 141
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: Peng Huo <penghuo@gmail.com>
- Loading branch information
Showing
41 changed files
with
1,682 additions
and
419 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
34 changes: 34 additions & 0 deletions
34
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,34 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Explain Statement. | ||
*/ | ||
@Getter | ||
@Setter | ||
@ToString | ||
@EqualsAndHashCode(callSuper = false) | ||
@RequiredArgsConstructor | ||
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); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
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,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.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 submitQuery(AbstractPlan queryExecution) { | ||
|
||
// 2. start query execution. | ||
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 submitQuery(AbstractPlan queryPlan); | ||
} |
70 changes: 70 additions & 0 deletions
70
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,70 @@ | ||
/* | ||
* 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.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. | ||
* | ||
* @param plan {@link UnresolvedPlan} | ||
* @param listener {@link ResponseListener} | ||
*/ | ||
public void execute(UnresolvedPlan plan, | ||
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(plan), listener); | ||
} catch (Exception e) { | ||
listener.onFailure(e); | ||
} | ||
} | ||
|
||
private PhysicalPlan plan(UnresolvedPlan plan) { | ||
// 1.Analyze abstract syntax to generate logical plan | ||
LogicalPlan logicalPlan = analyzer.analyze(plan, new AnalysisContext()); | ||
|
||
// 2.Generate optimal physical plan from logical plan | ||
return planner.plan(logicalPlan); | ||
} | ||
} |
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.