Skip to content

Commit

Permalink
Added <pre> header to java docs written incorrectly to retain forma…
Browse files Browse the repository at this point in the history
…tting.
  • Loading branch information
MitchellGale authored Jul 26, 2023
1 parent 25bfe09 commit c1174c4
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <pre>
* 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
* </pre>
*/
public class ExpressionReferenceOptimizer
extends ExpressionNodeVisitor<Expression, AnalysisContext> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,18 @@ 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))
* <pre>
* 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))
* </pre>
*/
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 @@ -75,12 +75,19 @@ public Optional<String> first() {
}

/**
* Get rest parts of the qualified name. Assume that there must be remaining parts so caller is
* responsible for the check (first() or size() must be called first). For example: {@code
* QualifiedName name = ... Optional<String> first = name.first(); if (first.isPresent()) {
* name.rest() ... } }
*
* @return rest part(s)
* <pre>
* Get rest parts of the qualified name. Assume that there must be remaining parts
* so caller is responsible for the check (first() or size() must be called first).
* For example:
* {@code
* QualifiedName name = ...
* Optional<String> first = name.first();
* if (first.isPresent()) {
* name.rest() ...
* }
* }
* @return rest part(s)
* </pre>
*/
public QualifiedName rest() {
return QualifiedName.of(parts.subList(1, parts.size()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum ExprCoreType implements ExprType {

/**
* Undefined type for special literal such as NULL. As the root of data type tree, it is
* compatible with any other type. In other word, undefined type is the "narrowest" type.
* compatible with any other type. In other words, undefined type is the "narrowest" type.
*/
UNDEFINED,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <pre>
* 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
* </pre>
*/
@UtilityClass
public class WideningTypeRule {
Expand Down Expand Up @@ -46,13 +55,16 @@ private static int distance(ExprType type1, ExprType type2, int distance) {
}

/**
* The max type among two types. The max is defined as follow if type1 could widen to type2, then
* max is type2, vice versa if type1 could't widen to type2 and type2 could't widen to type1, then
* throw {@link ExpressionEvaluationException}.
* <pre>
* The max type among two types. The max is defined as follow
* if type1 could widen to type2, then max is type2, vice versa
* if type1 could't widen to type2 and type2 could't widen to type1,
* then throw {@link ExpressionEvaluationException}.
*
* @param type1 type1
* @param type2 type2
* @return the max type among two types.
* </pre>
*/
public static ExprType max(ExprType type1, ExprType type2) {
int type1To2 = distance(type1, type2);
Expand Down

0 comments on commit c1174c4

Please sign in to comment.