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

[Backport 2.x] [Spotless] Applying Google Code Format for core/src/main files #1 #1930 #1992

Merged
merged 9 commits into from
Aug 22, 2023
Merged
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ spotless {
'core/src/test/java/org/opensearch/sql/analysis/**/*.java',
'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/utils/**/*.java'
exclude '**/build/**', '**/build-*/**'
}
importOrder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@
import org.opensearch.sql.planner.logical.LogicalWindow;

/**
* The optimizer used to replace the expression referred in the SelectClause e.g. The query SELECT
* abs(name), sum(age)-avg(age) FROM test GROUP BY abs(name). will be translated the AST
* Project[abs(age), sub(sum(age), avg(age)) Agg(agg=[sum(age), avg(age)], group=[abs(age)]]
* Relation The sum(age) and avg(age) in the Project could be replace by the analyzed reference, the
* LogicalPlan should be LogicalProject[Ref("abs(age)"), sub(Ref("sum(age)"), Ref("avg(age)"))
* LogicalAgg(agg=[sum(age), avg(age)], group=[abs(age)]] LogicalRelation
* The optimizer used to replace the expression referred in the SelectClause</br> e.g. The query
* SELECT abs(name), sum(age)-avg(age) FROM test GROUP BY abs(name).<br>
* will be translated the AST<br>
* Project[abs(age), sub(sum(age), avg(age))<br>
* &ensp Agg(agg=[sum(age), avg(age)], group=[abs(age)]]<br>
* &emsp Relation<br>
* The sum(age) and avg(age) in the Project could be replaced by the analyzed reference, the
* LogicalPlan should be<br>
* LogicalProject[Ref("abs(age)"), sub(Ref("sum(age)"), Ref("avg(age)"))<br>
* &ensp LogicalAgg(agg=[sum(age), avg(age)], group=[abs(age)]]<br>
* &emsp LogicalRelation
*/
public class ExpressionReferenceOptimizer
extends ExpressionNodeVisitor<Expression, AnalysisContext> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,17 @@ public List<NamedExpression> visitAlias(Alias node, AnalysisContext context) {
}

/**
* The Alias could be 1. SELECT name, AVG(age) FROM s BY name -> Project(Alias("name", expr),
* Alias("AVG(age)", aggExpr)) Agg(Alias("AVG(age)", aggExpr)) 2. SELECT length(name), AVG(age)
* FROM s BY length(name) Project(Alias("name", expr), Alias("AVG(age)", aggExpr))
* Agg(Alias("AVG(age)", aggExpr)) 3. SELECT length(name) as l, AVG(age) FROM s BY l
* Project(Alias("name", expr, l), Alias("AVG(age)", aggExpr)) Agg(Alias("AVG(age)", aggExpr),
* Alias("length(name)", groupExpr))
* The Alias could be
*
* <ol>
* <li>SELECT name, AVG(age) FROM s BY name -> Project(Alias("name", expr), Alias("AVG(age)",
* aggExpr)) Agg(Alias("AVG(age)", aggExpr))
* <li>SELECT length(name), AVG(age) FROM s BY length(name) Project(Alias("name", expr),
* Alias("AVG(age)", aggExpr)) Agg(Alias("AVG(age)", aggExpr))
* <li>SELECT length(name) as l, AVG(age) FROM s BY l Project(Alias("name", expr, l),
* Alias("AVG(age)", aggExpr)) Agg(Alias("AVG(age)", aggExpr), Alias("length(name)",
* groupExpr))
* </ol>
*/
private Expression referenceIfSymbolDefined(Alias expr, AnalysisContext context) {
UnresolvedExpression delegatedExpr = expr.getDelegated();
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.ast;

import org.opensearch.sql.ast.expression.AggregateFunction;
Expand Down Expand Up @@ -62,9 +61,7 @@
import org.opensearch.sql.ast.tree.TableFunction;
import org.opensearch.sql.ast.tree.Values;

/**
* AST nodes visitor Defines the traverse path.
*/
/** AST nodes visitor Defines the traverse path. */
public abstract class AbstractNodeVisitor<T, C> {

public T visit(Node node, C context) {
Expand All @@ -73,6 +70,7 @@ public T visit(Node node, C context) {

/**
* Visit child node.
*
* @param node {@link Node}
* @param context Context
* @return Return Type.
Expand Down
5 changes: 1 addition & 4 deletions core/src/main/java/org/opensearch/sql/ast/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.ast;

import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.ToString;

/**
* AST node.
*/
/** AST node. */
@EqualsAndHashCode
@ToString
public abstract class Node {
Expand Down
10 changes: 7 additions & 3 deletions core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,23 +249,27 @@ public static Function function(String funcName, UnresolvedExpression... funcArg
}

/**
* <pre>
* CASE
* WHEN search_condition THEN result_expr
* [WHEN search_condition THEN result_expr] ...
* [ELSE result_expr]
* WHEN search_condition THEN result_expr<br>
* [WHEN search_condition THEN result_expr] ...
* [ELSE result_expr]
* END
* </pre>
*/
public UnresolvedExpression caseWhen(UnresolvedExpression elseClause,
When... whenClauses) {
return caseWhen(null, elseClause, whenClauses);
}

/**
* <pre>
* CASE case_value_expr
* WHEN compare_expr THEN result_expr
* [WHEN compare_expr THEN result_expr] ...
* [ELSE result_expr]
* END
* </pre>
*/
public UnresolvedExpression caseWhen(UnresolvedExpression caseValueExpr,
UnresolvedExpression elseClause,
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.ast.expression;

import java.util.Collections;
Expand All @@ -17,8 +16,8 @@
import org.opensearch.sql.common.utils.StringUtils;

/**
* Expression node of aggregate functions.
* Params include aggregate function name (AVG, SUM, MAX etc.) and the field to aggregate.
* Expression node of aggregate functions. Params include aggregate function name (AVG, SUM, MAX
* etc.) and the field to aggregate.
*/
@Getter
@EqualsAndHashCode(callSuper = false)
Expand All @@ -27,13 +26,16 @@ public class AggregateFunction extends UnresolvedExpression {
private final String funcName;
private final UnresolvedExpression field;
private final List<UnresolvedExpression> argList;

@Setter
@Accessors(fluent = true)
private UnresolvedExpression condition;

private Boolean distinct = false;

/**
* Constructor.
*
* @param funcName function name.
* @param field {@link UnresolvedExpression}.
*/
Expand All @@ -45,6 +47,7 @@ public AggregateFunction(String funcName, UnresolvedExpression field) {

/**
* Constructor.
*
* @param funcName function name.
* @param field {@link UnresolvedExpression}.
* @param distinct whether distinct field is specified or not.
Expand Down
21 changes: 7 additions & 14 deletions core/src/main/java/org/opensearch/sql/ast/expression/Alias.java
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.ast.expression;

import lombok.AllArgsConstructor;
Expand All @@ -14,10 +13,10 @@
import org.opensearch.sql.ast.AbstractNodeVisitor;

/**
* Alias abstraction that associate an unnamed expression with a name and an optional alias.
* The name and alias information preserved is useful for semantic analysis and response
* formatting eventually. This can avoid restoring the info in toString() method which is
* inaccurate because original info is already lost.
* Alias abstraction that associate an unnamed expression with a name and an optional alias. The
* name and alias information preserved is useful for semantic analysis and response formatting
* eventually. This can avoid restoring the info in toString() method which is inaccurate because
* original info is already lost.
*/
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
Expand All @@ -26,19 +25,13 @@
@ToString
public class Alias extends UnresolvedExpression {

/**
* Original field name.
*/
/** Original field name. */
private final String name;

/**
* Expression aliased.
*/
/** Expression aliased. */
private final UnresolvedExpression delegated;

/**
* Optional field alias.
*/
/** Optional field alias. */
private String alias;

@Override
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.ast.expression;

import java.util.Collections;
Expand All @@ -13,16 +12,13 @@
import org.opensearch.sql.ast.AbstractNodeVisitor;
import org.opensearch.sql.ast.Node;

/**
* Represent the All fields which is been used in SELECT *.
*/
/** Represent the All fields which is been used in SELECT *. */
@ToString
@EqualsAndHashCode(callSuper = false)
public class AllFields extends UnresolvedExpression {
public static final AllFields INSTANCE = new AllFields();

private AllFields() {
}
private AllFields() {}

public static AllFields of() {
return INSTANCE;
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.ast.expression;

import java.util.Arrays;
Expand All @@ -14,9 +13,7 @@
import lombok.ToString;
import org.opensearch.sql.ast.AbstractNodeVisitor;

/**
* Expression node of logic AND.
*/
/** Expression node of logic AND. */
@Getter
@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.ast.expression;

import java.util.Arrays;
Expand All @@ -14,9 +13,7 @@
import lombok.ToString;
import org.opensearch.sql.ast.AbstractNodeVisitor;

/**
* Argument.
*/
/** Argument. */
@Getter
@ToString
@RequiredArgsConstructor
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.ast.expression;

import com.google.common.collect.ImmutableList;
Expand All @@ -14,15 +13,12 @@
import lombok.ToString;
import org.opensearch.sql.ast.AbstractNodeVisitor;

/**
* Expression node that includes a list of Expression nodes.
*/
/** Expression node that includes a list of Expression nodes. */
@ToString
@EqualsAndHashCode(callSuper = false)
@AllArgsConstructor
public class AttributeList extends UnresolvedExpression {
@Getter
private List<UnresolvedExpression> attrList;
@Getter private List<UnresolvedExpression> attrList;

@Override
public List<UnresolvedExpression> getChild() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import org.opensearch.sql.ast.AbstractNodeVisitor;
import org.opensearch.sql.ast.Node;

/**
* Unresolved expression for BETWEEN.
*/
/** Unresolved expression for BETWEEN. */
@Data
@EqualsAndHashCode(callSuper = false)
public class Between extends UnresolvedExpression {
Expand Down
18 changes: 5 additions & 13 deletions core/src/main/java/org/opensearch/sql/ast/expression/Case.java
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.ast.expression;

import com.google.common.collect.ImmutableList;
Expand All @@ -15,29 +14,23 @@
import org.opensearch.sql.ast.AbstractNodeVisitor;
import org.opensearch.sql.ast.Node;

/**
* AST node that represents CASE clause similar as Switch statement in programming language.
*/
/** AST node that represents CASE clause similar as Switch statement in programming language. */
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Getter
@ToString
public class Case extends UnresolvedExpression {

/**
* Value to be compared by WHEN statements. Null in the case of CASE WHEN conditions.
*/
/** Value to be compared by WHEN statements. Null in the case of CASE WHEN conditions. */
private final UnresolvedExpression caseValue;

/**
* Expression list that represents WHEN statements. Each is a mapping from condition
* to its result.
* Expression list that represents WHEN statements. Each is a mapping from condition to its
* result.
*/
private final List<When> whenClauses;

/**
* Expression that represents ELSE statement result.
*/
/** Expression that represents ELSE statement result. */
private final UnresolvedExpression elseClause;

@Override
Expand All @@ -58,5 +51,4 @@ public List<? extends Node> getChild() {
public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) {
return nodeVisitor.visitCase(this, context);
}

}
Loading
Loading