Skip to content

Commit

Permalink
[Backport 2.x] [Spotless] Applying Google Code Format for core/src/ma…
Browse files Browse the repository at this point in the history
…in files #3 (opensearch-project#1932) (opensearch-project#1994)

* [Spotless] Applying Google Code Format for core/src/main files #3 (opensearch-project#1932)

* Applying Google Java code format changes to core/src/main/java/org/opensearch/sql/planner core/src/main/java/org/opensearch/sql/storage core/src/main/java/org/opensearch/sql/utils

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

* Ignore on failure for checkstyle in core and added the three spotless fixes files.

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

* Fixed javadoc formatting in LogicalPlanOptimizer.java LogicalValues.java OperatorUtils.java Planner.java

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

* spotless apply, fixing include for spotless build.gradle and adding pre tag.

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

* addressed PR comments.

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

---------

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>
Signed-off-by: Mitchell Gale <Mitchell.gale@improving.com>

* spotless apply

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

* add checkstyle ignore

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

* addressed PR comments

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

---------

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>
Signed-off-by: Mitchell Gale <Mitchell.gale@improving.com>
  • Loading branch information
MitchellGale authored Aug 21, 2023
1 parent ed6ab58 commit 9f081ab
Show file tree
Hide file tree
Showing 91 changed files with 771 additions and 1,164 deletions.
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ repositories {
spotless {
java {
target fileTree('.') {
include '**/*.java'
include 'core/src/main/java/org/opensearch/sql/planner/**/*.java',
'core/src/main/java/org/opensearch/sql/storage/**/*.java',
'core/src/main/java/org/opensearch/sql/utils/**/*.java',
'core/src/main/java/org/opensearch/sql/monitor/**/*.java'
exclude '**/build/**', '**/build-*/**'
}
// importOrder()
Expand All @@ -95,7 +98,7 @@ spotless {
// removeUnusedImports()
// trimTrailingWhitespace()
endWithNewline()
// googleJavaFormat('1.17.0').reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format')
googleJavaFormat('1.17.0').reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format')
}
}

Expand Down
3 changes: 3 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ repositories {
mavenCentral()
}

checkstyleTest.ignoreFailures = true
checkstyleMain.ignoreFailures = true

dependencies {
api group: 'com.google.guava', name: 'guava', version: '32.0.1-jre'
api group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.monitor;

/**
* Always healthy resource monitor.
*/
/** Always healthy resource monitor. */
public class AlwaysHealthyMonitor extends ResourceMonitor {
public static final ResourceMonitor ALWAYS_HEALTHY_MONITOR =
new AlwaysHealthyMonitor();
public static final ResourceMonitor ALWAYS_HEALTHY_MONITOR = new AlwaysHealthyMonitor();

/**
* always healthy.
*/
/** always healthy. */
@Override
public boolean isHealthy() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.monitor;

/**
* The abstract interface of ResourceMonitor.
* When an fault is detected, the circuit breaker is open.
* The abstract interface of ResourceMonitor. When an fault is detected, the circuit breaker is
* open.
*/
public abstract class ResourceMonitor {
/**
Expand Down
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
48 changes: 22 additions & 26 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,17 +14,15 @@
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.
* Generate optimal physical plan for logical plan. If no table involved, translate logical plan
* to physical by default implementor.<br>
* TODO: for now just delegate entire logical plan to storage engine.
*
* @param plan logical 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
Loading

0 comments on commit 9f081ab

Please sign in to comment.