Skip to content

Commit

Permalink
revert ast changes as was covered in spotless #1 PR for GJF.
Browse files Browse the repository at this point in the history
Signed-off-by: Mitchell Gale <[email protected]>
  • Loading branch information
MitchellGale committed Aug 3, 2023
1 parent b95580d commit de6831d
Show file tree
Hide file tree
Showing 64 changed files with 373 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.ast;

import org.opensearch.sql.ast.expression.AggregateFunction;
Expand Down Expand Up @@ -61,7 +62,9 @@
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 @@ -70,7 +73,6 @@ public T visit(Node node, C context) {

/**
* Visit child node.
*
* @param node {@link Node}
* @param context Context
* @return Return Type.
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/org/opensearch/sql/ast/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
* 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
2 changes: 1 addition & 1 deletion core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -465,4 +465,4 @@ public static Parse parse(UnresolvedPlan input, ParseMethod parseMethod,
return new Parse(parseMethod, sourceField, pattern, arguments, input);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.opensearch.sql.common.utils.StringUtils;

/**
* Expression node of aggregate functions.<br>
* Expression node of aggregate functions.
* Params include aggregate function name (AVG, SUM, MAX etc.) and the field to aggregate.
*/
@Getter
Expand Down
21 changes: 14 additions & 7 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,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.ast.expression;

import lombok.AllArgsConstructor;
Expand All @@ -13,10 +14,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 @@ -25,13 +26,19 @@
@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,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.ast.expression;

import java.util.Collections;
Expand All @@ -12,13 +13,16 @@
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,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.ast.expression;

import java.util.Arrays;
Expand All @@ -13,7 +14,9 @@
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,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.ast.expression;

import java.util.Arrays;
Expand All @@ -13,7 +14,9 @@
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,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.ast.expression;

import com.google.common.collect.ImmutableList;
Expand All @@ -13,12 +14,15 @@
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,7 +12,9 @@
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: 13 additions & 5 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,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.ast.expression;

import com.google.common.collect.ImmutableList;
Expand All @@ -14,23 +15,29 @@
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 @@ -51,4 +58,5 @@ public List<? extends Node> getChild() {
public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) {
return nodeVisitor.visitCase(this, context);
}

}
49 changes: 27 additions & 22 deletions core/src/main/java/org/opensearch/sql/ast/expression/Cast.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.ast.expression;

import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_BOOLEAN;
Expand Down Expand Up @@ -32,40 +33,45 @@
import org.opensearch.sql.data.type.ExprType;
import org.opensearch.sql.expression.function.FunctionName;

/** AST node that represents Cast clause. */
/**
* AST node that represents Cast clause.
*/
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Getter
@ToString
public class Cast extends UnresolvedExpression {

private static final Map<String, FunctionName> CONVERTED_TYPE_FUNCTION_NAME_MAP =
new ImmutableMap.Builder<String, FunctionName>()
.put("string", CAST_TO_STRING.getName())
.put("byte", CAST_TO_BYTE.getName())
.put("short", CAST_TO_SHORT.getName())
.put("int", CAST_TO_INT.getName())
.put("integer", CAST_TO_INT.getName())
.put("long", CAST_TO_LONG.getName())
.put("float", CAST_TO_FLOAT.getName())
.put("double", CAST_TO_DOUBLE.getName())
.put("boolean", CAST_TO_BOOLEAN.getName())
.put("date", CAST_TO_DATE.getName())
.put("time", CAST_TO_TIME.getName())
.put("timestamp", CAST_TO_TIMESTAMP.getName())
.put("datetime", CAST_TO_DATETIME.getName())
.build();
new ImmutableMap.Builder<String, FunctionName>()
.put("string", CAST_TO_STRING.getName())
.put("byte", CAST_TO_BYTE.getName())
.put("short", CAST_TO_SHORT.getName())
.put("int", CAST_TO_INT.getName())
.put("integer", CAST_TO_INT.getName())
.put("long", CAST_TO_LONG.getName())
.put("float", CAST_TO_FLOAT.getName())
.put("double", CAST_TO_DOUBLE.getName())
.put("boolean", CAST_TO_BOOLEAN.getName())
.put("date", CAST_TO_DATE.getName())
.put("time", CAST_TO_TIME.getName())
.put("timestamp", CAST_TO_TIMESTAMP.getName())
.put("datetime", CAST_TO_DATETIME.getName())
.build();

/** The source expression cast from. */
/**
* The source expression cast from.
*/
private final UnresolvedExpression expression;

/** Expression that represents name of the target type. */
/**
* Expression that represents name of the target type.
*/
private final UnresolvedExpression convertedType;

/**
* Check if the given function name is a cast function or not.
*
* @param name function name
* @param name function name
* @return true if cast function, otherwise false.
*/
public static boolean isCastFunction(FunctionName name) {
Expand All @@ -74,8 +80,7 @@ public static boolean isCastFunction(FunctionName name) {

/**
* Get the cast function name for a given target data type.
*
* @param targetType target data type
* @param targetType target data type
* @return cast function name corresponding
*/
public static FunctionName getCastFunctionName(ExprType targetType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.ast.expression;

import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.ast.expression;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.opensearch.sql.data.type.ExprCoreType;

/** The DataType defintion in AST. Question, could we use {@link ExprCoreType} directly in AST? */
/**
* The DataType defintion in AST.
* Question, could we use {@link ExprCoreType} directly in AST?
*/
@RequiredArgsConstructor
public enum DataType {
TYPE_ERROR(ExprCoreType.UNKNOWN),
Expand All @@ -28,5 +32,6 @@ public enum DataType {
TIMESTAMP(ExprCoreType.TIMESTAMP),
INTERVAL(ExprCoreType.INTERVAL);

@Getter private final ExprCoreType coreType;
@Getter
private final ExprCoreType coreType;
}
Loading

0 comments on commit de6831d

Please sign in to comment.