Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spotless] Applying Google Code Format for core/src/main files #3 #314

Merged
merged 4 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ repositories {
// Spotless checks will be added as PRs are applied to resolve each style issue is approved.
spotless {
java {
// target fileTree('.') {
// include '**/*.java', 'src/*/java/**/*.java'
// exclude '**/build/**', '**/build-*/**'
// }
target fileTree('.') {
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'
exclude '**/build/**', '**/build-*/**'
}
// importOrder()
// licenseHeader("/*\n" +
// " * Copyright OpenSearch Contributors\n" +
Expand All @@ -95,7 +97,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 @@ -34,6 +34,9 @@ repositories {
mavenCentral()
}

checkstyleTest.ignoreFailures = true
checkstyleMain.ignoreFailures = true

pitest {
targetClasses = ['org.opensearch.sql.*']
pitestVersion = '1.9.0'
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
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
Loading