Skip to content

Commit

Permalink
Merge pull request opensearch-project#1078 from penghuo/feature/maxim…
Browse files Browse the repository at this point in the history
…us/2.x

Merge feature/maximus-m1 to 2.x
  • Loading branch information
penghuo authored Nov 16, 2022
2 parents 662a938 + 7f107a4 commit 0504c71
Show file tree
Hide file tree
Showing 114 changed files with 4,265 additions and 1,081 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/sql-test-and-build-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
matrix:
entry:
- { os: ubuntu-latest, java: 11 }
- { os: windows-latest, java: 11, os_build_args: -x doctest -x integTest -x jacocoTestReport -x compileJdbc}
- { os: windows-latest, java: 11, os_build_args: -x doctest -x integTest -x jacocoTestReport -x compileJdbc -PbuildPlatform=windows }
- { os: macos-latest, java: 11, os_build_args: -x doctest -x integTest -x jacocoTestReport -x compileJdbc }
- { os: ubuntu-latest, java: 17 }
- { os: windows-latest, java: 17, os_build_args: -x doctest -x integTest -x jacocoTestReport -x compileJdbc }
- { os: windows-latest, java: 17, os_build_args: -x doctest -x integTest -x jacocoTestReport -x compileJdbc -PbuildPlatform=windows }
- { os: macos-latest, java: 17, os_build_args: -x doctest -x integTest -x jacocoTestReport -x compileJdbc }
runs-on: ${{ matrix.entry.os }}

Expand Down
15 changes: 15 additions & 0 deletions core/src/main/java/org/opensearch/sql/ast/AbstractNodeVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
import org.opensearch.sql.ast.expression.When;
import org.opensearch.sql.ast.expression.WindowFunction;
import org.opensearch.sql.ast.expression.Xor;
import org.opensearch.sql.ast.statement.Explain;
import org.opensearch.sql.ast.statement.Query;
import org.opensearch.sql.ast.statement.Statement;
import org.opensearch.sql.ast.tree.AD;
import org.opensearch.sql.ast.tree.Aggregation;
import org.opensearch.sql.ast.tree.Dedupe;
Expand Down Expand Up @@ -274,4 +277,16 @@ public T visitML(ML node, C context) {
public T visitHighlightFunction(HighlightFunction node, C context) {
return visitChildren(node, context);
}

public T visitStatement(Statement node, C context) {
return visit(node, context);
}

public T visitQuery(Query node, C context) {
return visitStatement(node, context);
}

public T visitExplain(Explain node, C context) {
return visitStatement(node, context);
}
}
26 changes: 26 additions & 0 deletions core/src/main/java/org/opensearch/sql/ast/statement/Explain.java
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 core/src/main/java/org/opensearch/sql/ast/statement/Query.java
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 core/src/main/java/org/opensearch/sql/ast/statement/Statement.java
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);
}
}
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 core/src/main/java/org/opensearch/sql/executor/QueryId.java
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 core/src/main/java/org/opensearch/sql/executor/QueryManager.java
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 core/src/main/java/org/opensearch/sql/executor/QueryService.java
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);
}
}
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);
}
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.");
}
}
Loading

0 comments on commit 0504c71

Please sign in to comment.