Skip to content

Commit

Permalink
Applying Google Java code format changes to core/src/main/java/org/op…
Browse files Browse the repository at this point in the history
…ensearch/sql/planner core/src/main/java/org/opensearch/sql/storage core/src/main/java/org/opensearch/sql/utils

Signed-off-by: Mitchell Gale <[email protected]>
  • Loading branch information
MitchellGale committed Jul 25, 2023
1 parent af12c02 commit 8bb4117
Show file tree
Hide file tree
Showing 87 changed files with 747 additions and 1,160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@

/**
* Default implementor for implementing logical to physical translation. "Default" here means all
* logical operator will be translated to correspondent physical operator to pipeline operations
* in post-processing style in memory.
* Different storage can override methods here to optimize default pipelining operator, for example
* a storage has the flexibility to override visitFilter and visitRelation to push down filtering
* operation and return a single physical index scan operator.
* logical operator will be translated to correspondent physical operator to pipeline operations in
* post-processing style in memory. Different storage can override methods here to optimize default
* pipelining operator, for example a storage has the flexibility to override visitFilter and
* visitRelation to push down filtering operation and return a single physical index scan operator.
*
* @param <C> context type
* @param <C> context type
*/
public class DefaultImplementor<C> extends LogicalPlanNodeVisitor<PhysicalPlan, C> {

Expand All @@ -62,8 +61,7 @@ public PhysicalPlan visitRareTopN(LogicalRareTopN node, C context) {
node.getCommandType(),
node.getNoOfResults(),
node.getFieldList(),
node.getGroupByList()
);
node.getGroupByList());
}

@Override
Expand All @@ -78,16 +76,14 @@ public PhysicalPlan visitDedupe(LogicalDedupe node, C context) {

@Override
public PhysicalPlan visitProject(LogicalProject node, C context) {
return new ProjectOperator(visitChild(node, context), node.getProjectList(),
node.getNamedParseExpressions());
return new ProjectOperator(
visitChild(node, context), node.getProjectList(), node.getNamedParseExpressions());
}

@Override
public PhysicalPlan visitWindow(LogicalWindow node, C context) {
return new WindowOperator(
visitChild(node, context),
node.getWindowFunction(),
node.getWindowDefinition());
visitChild(node, context), node.getWindowFunction(), node.getWindowDefinition());
}

@Override
Expand Down Expand Up @@ -148,8 +144,9 @@ public PhysicalPlan visitTableWriteBuilder(TableWriteBuilder plan, C context) {

@Override
public PhysicalPlan visitRelation(LogicalRelation node, C context) {
throw new UnsupportedOperationException("Storage engine is responsible for "
+ "implementing and optimizing logical plan with relation involved");
throw new UnsupportedOperationException(
"Storage engine is responsible for "
+ "implementing and optimizing logical plan with relation involved");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@
import lombok.Getter;
import org.opensearch.sql.storage.split.Split;

/**
* Plan context hold planning related information.
*/
/** Plan context hold planning related information. */
public class PlanContext {

@Getter
private final Optional<Split> split;
@Getter private final Optional<Split> split;

public PlanContext(Split split) {
this.split = Optional.of(split);
Expand Down
5 changes: 1 addition & 4 deletions core/src/main/java/org/opensearch/sql/planner/PlanNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.planner;

import java.util.List;

/**
* The definition of Plan Node.
*/
/** The definition of Plan Node. */
public interface PlanNode<T extends PlanNode> {

/**
Expand Down
50 changes: 23 additions & 27 deletions core/src/main/java/org/opensearch/sql/planner/Planner.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.planner;


import java.util.List;
import lombok.RequiredArgsConstructor;
import org.opensearch.sql.planner.logical.LogicalPlan;
Expand All @@ -16,18 +14,16 @@
import org.opensearch.sql.planner.physical.PhysicalPlan;
import org.opensearch.sql.storage.Table;

/**
* Planner that plans and chooses the optimal physical plan.
*/
/** Planner that plans and chooses the optimal physical plan. */
@RequiredArgsConstructor
public class Planner {

private final LogicalPlanOptimizer logicalOptimizer;

/**
* Generate optimal physical plan for logical plan. If no table involved,
* translate logical plan to physical by default implementor.
* TODO: for now just delegate entire logical plan to storage engine.
* Generate optimal physical plan for logical plan. If no table involved, translate logical plan
* to physical by default implementor. TODO: for now just delegate entire logical plan to storage
* engine.
*
* @param plan logical plan
* @return optimal physical plan
Expand All @@ -37,28 +33,28 @@ public PhysicalPlan plan(LogicalPlan plan) {
if (table == null) {
return plan.accept(new DefaultImplementor<>(), null);
}
return table.implement(
table.optimize(optimize(plan)));
return table.implement(table.optimize(optimize(plan)));
}

private Table findTable(LogicalPlan plan) {
return plan.accept(new LogicalPlanNodeVisitor<Table, Object>() {

@Override
public Table visitNode(LogicalPlan node, Object context) {
List<LogicalPlan> children = node.getChild();
if (children.isEmpty()) {
return null;
}
return children.get(0).accept(this, context);
}

@Override
public Table visitRelation(LogicalRelation node, Object context) {
return node.getTable();
}

}, null);
return plan.accept(
new LogicalPlanNodeVisitor<Table, Object>() {

@Override
public Table visitNode(LogicalPlan node, Object context) {
List<LogicalPlan> children = node.getChild();
if (children.isEmpty()) {
return null;
}
return children.get(0).accept(this, context);
}

@Override
public Table visitRelation(LogicalRelation node, Object context) {
return node.getTable();
}
},
null);
}

private LogicalPlan optimize(LogicalPlan plan) {
Expand Down
35 changes: 18 additions & 17 deletions core/src/main/java/org/opensearch/sql/planner/SerializablePlan.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,37 @@
/**
* All subtypes of PhysicalPlan which needs to be serialized (in cursor, for pagination feature)
* should follow one of the following options.
*
* <ul>
* <li>Both:
* <ul>
* <li>Override both methods from {@link Externalizable}.</li>
* <li>Define a public no-arg constructor.</li>
* </ul>
* </li>
* <li>
* Overwrite {@link #getPlanForSerialization} to return
* another instance of {@link SerializablePlan}.
* </li>
* <ul>
* <li>Override both methods from {@link Externalizable}.
* <li>Define a public no-arg constructor.
* </ul>
* <li>Overwrite {@link #getPlanForSerialization} to return another instance of {@link
* SerializablePlan}.
* </ul>
*/
public interface SerializablePlan extends Externalizable {

/**
* Override to return child or delegated plan, so parent plan should skip this one
* for serialization, but it should try to serialize grandchild plan.
* Imagine plan structure like this
* Override to return child or delegated plan, so parent plan should skip this one for
* serialization, but it should try to serialize grandchild plan. Imagine plan structure like this
*
* <pre>
* A -> this
* `- B -> child
* `- C -> this
* </pre>
* In that case only plans A and C should be attempted to serialize.
* It is needed to skip a `ResourceMonitorPlan` instance only, actually.
*
* <pre>{@code
* * A.writeObject(B.getPlanForSerialization());
* }</pre>
* In that case only plans A and C should be attempted to serialize. It is needed to skip a
* `ResourceMonitorPlan` instance only, actually.
*
* <pre>{@code
* * A.writeObject(B.getPlanForSerialization());
*
* }</pre>
*
* @return Next plan for serialization.
*/
default SerializablePlan getPlanForSerialization() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class LogicalAD extends LogicalPlan {

/**
* Constructor of LogicalAD.
*
* @param child child logical plan
* @param arguments arguments of the algorithm
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.planner.logical;

import java.util.Collections;
Expand All @@ -14,26 +13,18 @@
import org.opensearch.sql.expression.NamedExpression;
import org.opensearch.sql.expression.aggregation.NamedAggregator;

/**
* Logical Aggregation.
*/
/** Logical Aggregation. */
@ToString
@EqualsAndHashCode(callSuper = true)
public class LogicalAggregation extends LogicalPlan {

@Getter
private final List<NamedAggregator> aggregatorList;
@Getter private final List<NamedAggregator> aggregatorList;

@Getter
private final List<NamedExpression> groupByList;
@Getter private final List<NamedExpression> groupByList;

/**
* Constructor of LogicalAggregation.
*/
/** Constructor of LogicalAggregation. */
public LogicalAggregation(
LogicalPlan child,
List<NamedAggregator> aggregatorList,
List<NamedExpression> groupByList) {
LogicalPlan child, List<NamedAggregator> aggregatorList, List<NamedExpression> groupByList) {
super(Collections.singletonList(child));
this.aggregatorList = aggregatorList;
this.groupByList = groupByList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import lombok.ToString;

/**
* A logical plan node which wraps {@link org.opensearch.sql.planner.LogicalCursor}
* and represent a cursor close operation.
* A logical plan node which wraps {@link org.opensearch.sql.planner.LogicalCursor} and represent a
* cursor close operation.
*/
@ToString
@EqualsAndHashCode(callSuper = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.planner.logical;

import java.util.Arrays;
Expand All @@ -13,9 +12,7 @@
import lombok.ToString;
import org.opensearch.sql.expression.Expression;

/**
* Logical Dedupe Plan.
*/
/** Logical Dedupe Plan. */
@Getter
@ToString
@EqualsAndHashCode(callSuper = true)
Expand All @@ -26,12 +23,12 @@ public class LogicalDedupe extends LogicalPlan {
private final Boolean keepEmpty;
private final Boolean consecutive;

/**
* Constructor of LogicalDedupe.
*/
/** Constructor of LogicalDedupe. */
public LogicalDedupe(
LogicalPlan child,
List<Expression> dedupeList, Integer allowedDuplication, Boolean keepEmpty,
List<Expression> dedupeList,
Integer allowedDuplication,
Boolean keepEmpty,
Boolean consecutive) {
super(Arrays.asList(child));
this.dedupeList = dedupeList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.planner.logical;

import java.util.Collections;
Expand All @@ -24,15 +23,10 @@
@EqualsAndHashCode(callSuper = true)
public class LogicalEval extends LogicalPlan {

@Getter
private final List<Pair<ReferenceExpression, Expression>> expressions;
@Getter private final List<Pair<ReferenceExpression, Expression>> expressions;

/**
* Constructor of LogicalEval.
*/
public LogicalEval(
LogicalPlan child,
List<Pair<ReferenceExpression, Expression>> expressions) {
/** Constructor of LogicalEval. */
public LogicalEval(LogicalPlan child, List<Pair<ReferenceExpression, Expression>> expressions) {
super(Collections.singletonList(child));
this.expressions = expressions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,17 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.opensearch.sql.planner.logical.LogicalPlan;
import org.opensearch.sql.planner.logical.LogicalPlanNodeVisitor;
import org.opensearch.sql.storage.StorageEngine;

/**
* A plan node which represents operation of fetching a next page from the cursor.
*/
/** A plan node which represents operation of fetching a next page from the cursor. */
@EqualsAndHashCode(callSuper = false)
@ToString
public class LogicalFetchCursor extends LogicalPlan {
@Getter
private final String cursor;
@Getter private final String cursor;

@Getter
private final StorageEngine engine;
@Getter private final StorageEngine engine;

/**
* LogicalCursor constructor. Does not have child plans.
*/
/** LogicalCursor constructor. Does not have child plans. */
public LogicalFetchCursor(String cursor, StorageEngine engine) {
super(List.of());
this.cursor = cursor;
Expand Down
Loading

0 comments on commit 8bb4117

Please sign in to comment.