From 7d55f5a9f3ad0f7440d3f71e10d24c5223e10c89 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Fri, 28 Jul 2023 01:05:47 -0700 Subject: [PATCH] Adding pre tag to javadocs that need to maintain old formatting. --- .../ExpressionReferenceOptimizer.java | 19 +++++++++++++------ .../analysis/SelectExpressionAnalyzer.java | 18 ++++++++++++------ .../org/opensearch/sql/ast/dsl/AstDSL.java | 9 +++++++-- .../sql/data/type/WideningTypeRule.java | 15 ++++++++++++--- 4 files changed, 44 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/org/opensearch/sql/analysis/ExpressionReferenceOptimizer.java b/core/src/main/java/org/opensearch/sql/analysis/ExpressionReferenceOptimizer.java index 8fb30fdbbf..dd59a7b79e 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/ExpressionReferenceOptimizer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/ExpressionReferenceOptimizer.java @@ -25,12 +25,19 @@ 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
+ * 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
+ * 
*/ public class ExpressionReferenceOptimizer extends ExpressionNodeVisitor { diff --git a/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java b/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java index be1ae2d235..e040c882c6 100644 --- a/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java +++ b/core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java @@ -70,12 +70,18 @@ public List 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
+   * 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))
+   * 
*/ private Expression referenceIfSymbolDefined(Alias expr, AnalysisContext context) { UnresolvedExpression delegatedExpr = expr.getDelegated(); diff --git a/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java b/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java index c9ca9cc40a..1d6b612887 100644 --- a/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java +++ b/core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java @@ -247,8 +247,13 @@ public static Function function(String funcName, UnresolvedExpression... funcArg } /** - * CASE WHEN search_condition THEN result_expr [WHEN search_condition THEN result_expr] ... [ELSE - * result_expr] END + *
+   * CASE
+   *     WHEN search_condition THEN result_expr
+   *     [WHEN search_condition THEN result_expr] ...
+   *     [ELSE result_expr]
+   * END
+   * 
*/ public UnresolvedExpression caseWhen(UnresolvedExpression elseClause, When... whenClauses) { return caseWhen(null, elseClause, whenClauses); diff --git a/core/src/main/java/org/opensearch/sql/data/type/WideningTypeRule.java b/core/src/main/java/org/opensearch/sql/data/type/WideningTypeRule.java index bcec7bf318..7f8936e00c 100644 --- a/core/src/main/java/org/opensearch/sql/data/type/WideningTypeRule.java +++ b/core/src/main/java/org/opensearch/sql/data/type/WideningTypeRule.java @@ -11,9 +11,18 @@ import org.opensearch.sql.exception.ExpressionEvaluationException; /** - * The definition of widening type rule for expression value. ExprType Widens to data types INTEGER - * LONG, FLOAT, DOUBLE LONG FLOAT, DOUBLE FLOAT DOUBLE DOUBLE DOUBLE STRING STRING BOOLEAN BOOLEAN - * ARRAY ARRAY STRUCT STRUCT + *
+ * The definition of widening type rule for expression value.
+ * ExprType     Widens to data types
+ * INTEGER      LONG, FLOAT, DOUBLE
+ * LONG         FLOAT, DOUBLE
+ * FLOAT        DOUBLE
+ * DOUBLE       DOUBLE
+ * STRING       STRING
+ * BOOLEAN      BOOLEAN
+ * ARRAY        ARRAY
+ * STRUCT       STRUCT
+ * 
*/ @UtilityClass public class WideningTypeRule {