Skip to content

Commit

Permalink
[Spotless] Applying Google Code Format for core/src/main files #3 (op…
Browse files Browse the repository at this point in the history
…ensearch-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 <[email protected]>

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

Signed-off-by: Mitchell Gale <[email protected]>

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

Signed-off-by: Mitchell Gale <[email protected]>

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

Signed-off-by: Mitchell Gale <[email protected]>

* addressed PR comments.

Signed-off-by: Mitchell Gale <[email protected]>

---------

Signed-off-by: Mitchell Gale <[email protected]>
Signed-off-by: Mitchell Gale <[email protected]>
  • Loading branch information
MitchellGale committed Aug 18, 2023
1 parent d9a78df commit f1b35be
Show file tree
Hide file tree
Showing 88 changed files with 778 additions and 1,151 deletions.
26 changes: 21 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,17 @@ 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',
'core/src/main/java/org/opensearch/sql/expression/**/*.java',
'core/src/main/java/org/opensearch/sql/executor/**/*.java',
'core/src/main/java/org/opensearch/sql/exception/**/*.java',
'core/src/main/java/org/opensearch/sql/analysis/**/*.java',
'core/src/test/java/org/opensearch/sql/data/**/*.java',
'core/src/test/java/org/opensearch/sql/datasource/**/*.java',
'core/src/test/java/org/opensearch/sql/ast/**/*.java'
exclude '**/build/**', '**/build-*/**'
}
// importOrder()
Expand All @@ -95,7 +105,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 All @@ -113,9 +123,8 @@ allprojects {
sourceCompatibility = targetCompatibility = "11"
}
configurations.all {
resolutionStrategy.force "com.squareup.okio:okio:3.5.0"
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:1.9.0"
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.0"
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:1.6.0"
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib-common:1.6.0"
}
}

Expand Down Expand Up @@ -217,5 +226,12 @@ task updateVersion {
println "Setting version to ${newVersion}."
// String tokenization to support -SNAPSHOT
ant.replaceregexp(file:'build.gradle', match: '"opensearch.version", "\\d.*"', replace: '"opensearch.version", "' + newVersion.tokenize('-')[0] + '-SNAPSHOT"', flags:'g', byline:true)
ant.replaceregexp(match:'"version": "\\d+.\\d+.\\d+.\\d+', replace:'"version": ' + '"' + newVersion.tokenize('-')[0] + '.0', flags:'g', byline:true) {
fileset(dir: projectDir) {
include(name: "workbench/package.json")
include(name: "workbench/opensearch_dashboards.json")
}
}
ant.replaceregexp(file:'workbench/opensearch_dashboards.json', match:'"opensearchDashboardsVersion": "\\d+.\\d+.\\d+', replace:'"opensearchDashboardsVersion": ' + '"' + newVersion.tokenize('-')[0], flags:'g', byline:true)
}
}
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 f1b35be

Please sign in to comment.