Skip to content

Commit a43d97d

Browse files
committed
Fixing spacing around headers in ExpressionReferenceOptimizer.java SelectExpressionAnalyzer.java
Signed-off-by: Mitchell Gale <[email protected]>
1 parent 7469139 commit a43d97d

File tree

2 files changed

+62
-68
lines changed

2 files changed

+62
-68
lines changed

core/src/main/java/org/opensearch/sql/analysis/ExpressionReferenceOptimizer.java

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
76
package org.opensearch.sql.analysis;
87

98
import java.util.HashMap;
@@ -26,8 +25,8 @@
2625
import org.opensearch.sql.planner.logical.LogicalWindow;
2726

2827
/**
29-
* The optimizer used to replace the expression referred in the SelectClause</br>
30-
* e.g. The query SELECT abs(name), sum(age)-avg(age) FROM test GROUP BY abs(name).<br>
28+
* The optimizer used to replace the expression referred in the SelectClause</br> e.g. The query
29+
* SELECT abs(name), sum(age)-avg(age) FROM test GROUP BY abs(name).<br>
3130
* will be translated the AST<br>
3231
* Project[abs(age), sub(sum(age), avg(age))<br>
3332
* &ensp Agg(agg=[sum(age), avg(age)], group=[abs(age)]]<br>
@@ -43,8 +42,8 @@ public class ExpressionReferenceOptimizer
4342
private final BuiltinFunctionRepository repository;
4443

4544
/**
46-
* The map of expression and it's reference.
47-
* For example, The NamedAggregator should produce the map of Aggregator to Ref(name)
45+
* The map of expression and it's reference. For example, The NamedAggregator should produce the
46+
* map of Aggregator to Ref(name)
4847
*/
4948
private final Map<Expression, Expression> expressionMap = new HashMap<>();
5049

@@ -69,17 +68,16 @@ public Expression visitFunction(FunctionExpression node, AnalysisContext context
6968
return expressionMap.get(node);
7069
} else {
7170
final List<Expression> args =
72-
node.getArguments().stream().map(expr -> expr.accept(this, context))
71+
node.getArguments().stream()
72+
.map(expr -> expr.accept(this, context))
7373
.collect(Collectors.toList());
74-
Expression optimizedFunctionExpression = (Expression) repository.compile(
75-
context.getFunctionProperties(),
76-
node.getFunctionName(),
77-
args
78-
);
74+
Expression optimizedFunctionExpression =
75+
(Expression)
76+
repository.compile(context.getFunctionProperties(), node.getFunctionName(), args);
7977
// Propagate scoreTracked for OpenSearch functions
8078
if (optimizedFunctionExpression instanceof OpenSearchFunctions.OpenSearchFunction) {
81-
((OpenSearchFunctions.OpenSearchFunction) optimizedFunctionExpression).setScoreTracked(
82-
((OpenSearchFunctions.OpenSearchFunction)node).isScoreTracked());
79+
((OpenSearchFunctions.OpenSearchFunction) optimizedFunctionExpression)
80+
.setScoreTracked(((OpenSearchFunctions.OpenSearchFunction) node).isScoreTracked());
8381
}
8482
return optimizedFunctionExpression;
8583
}
@@ -98,19 +96,17 @@ public Expression visitNamed(NamedExpression node, AnalysisContext context) {
9896
return node.getDelegated().accept(this, context);
9997
}
10098

101-
/**
102-
* Implement this because Case/When is not registered in function repository.
103-
*/
99+
/** Implement this because Case/When is not registered in function repository. */
104100
@Override
105101
public Expression visitCase(CaseClause node, AnalysisContext context) {
106102
if (expressionMap.containsKey(node)) {
107103
return expressionMap.get(node);
108104
}
109105

110-
List<WhenClause> whenClauses = node.getWhenClauses()
111-
.stream()
112-
.map(expr -> (WhenClause) expr.accept(this, context))
113-
.collect(Collectors.toList());
106+
List<WhenClause> whenClauses =
107+
node.getWhenClauses().stream()
108+
.map(expr -> (WhenClause) expr.accept(this, context))
109+
.collect(Collectors.toList());
114110
Expression defaultResult = null;
115111
if (node.getDefaultResult() != null) {
116112
defaultResult = node.getDefaultResult().accept(this, context);
@@ -121,14 +117,10 @@ public Expression visitCase(CaseClause node, AnalysisContext context) {
121117
@Override
122118
public Expression visitWhen(WhenClause node, AnalysisContext context) {
123119
return new WhenClause(
124-
node.getCondition().accept(this, context),
125-
node.getResult().accept(this, context));
120+
node.getCondition().accept(this, context), node.getResult().accept(this, context));
126121
}
127122

128-
129-
/**
130-
* Expression Map Builder.
131-
*/
123+
/** Expression Map Builder. */
132124
class ExpressionMapBuilder extends LogicalPlanNodeVisitor<Void, Void> {
133125

134126
@Override
@@ -140,20 +132,27 @@ public Void visitNode(LogicalPlan plan, Void context) {
140132
@Override
141133
public Void visitAggregation(LogicalAggregation plan, Void context) {
142134
// Create the mapping for all the aggregator.
143-
plan.getAggregatorList().forEach(namedAggregator -> expressionMap
144-
.put(namedAggregator.getDelegated(),
145-
new ReferenceExpression(namedAggregator.getName(), namedAggregator.type())));
135+
plan.getAggregatorList()
136+
.forEach(
137+
namedAggregator ->
138+
expressionMap.put(
139+
namedAggregator.getDelegated(),
140+
new ReferenceExpression(namedAggregator.getName(), namedAggregator.type())));
146141
// Create the mapping for all the group by.
147-
plan.getGroupByList().forEach(groupBy -> expressionMap
148-
.put(groupBy.getDelegated(),
149-
new ReferenceExpression(groupBy.getNameOrAlias(), groupBy.type())));
142+
plan.getGroupByList()
143+
.forEach(
144+
groupBy ->
145+
expressionMap.put(
146+
groupBy.getDelegated(),
147+
new ReferenceExpression(groupBy.getNameOrAlias(), groupBy.type())));
150148
return null;
151149
}
152150

153151
@Override
154152
public Void visitWindow(LogicalWindow plan, Void context) {
155153
Expression windowFunc = plan.getWindowFunction();
156-
expressionMap.put(windowFunc,
154+
expressionMap.put(
155+
windowFunc,
157156
new ReferenceExpression(((NamedExpression) windowFunc).getName(), windowFunc.type()));
158157
return visitNode(plan, context);
159158
}

core/src/main/java/org/opensearch/sql/analysis/SelectExpressionAnalyzer.java

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
76
package org.opensearch.sql.analysis;
87

98
import com.google.common.collect.ImmutableList;
@@ -30,23 +29,21 @@
3029
import org.opensearch.sql.expression.ReferenceExpression;
3130

3231
/**
33-
* Analyze the select list in the {@link AnalysisContext} to construct the list of
34-
* {@link NamedExpression}.
32+
* Analyze the select list in the {@link AnalysisContext} to construct the list of {@link
33+
* NamedExpression}.
3534
*/
3635
@RequiredArgsConstructor
3736
public class SelectExpressionAnalyzer
38-
extends
39-
AbstractNodeVisitor<List<NamedExpression>, AnalysisContext> {
37+
extends AbstractNodeVisitor<List<NamedExpression>, AnalysisContext> {
4038
private final ExpressionAnalyzer expressionAnalyzer;
4139

4240
private ExpressionReferenceOptimizer optimizer;
4341

44-
/**
45-
* Analyze Select fields.
46-
*/
47-
public List<NamedExpression> analyze(List<UnresolvedExpression> selectList,
48-
AnalysisContext analysisContext,
49-
ExpressionReferenceOptimizer optimizer) {
42+
/** Analyze Select fields. */
43+
public List<NamedExpression> analyze(
44+
List<UnresolvedExpression> selectList,
45+
AnalysisContext analysisContext,
46+
ExpressionReferenceOptimizer optimizer) {
5047
this.optimizer = optimizer;
5148
ImmutableList.Builder<NamedExpression> builder = new ImmutableList.Builder<>();
5249
for (UnresolvedExpression unresolvedExpression : selectList) {
@@ -68,10 +65,8 @@ public List<NamedExpression> visitAlias(Alias node, AnalysisContext context) {
6865
}
6966

7067
Expression expr = referenceIfSymbolDefined(node, context);
71-
return Collections.singletonList(DSL.named(
72-
unqualifiedNameIfFieldOnly(node, context),
73-
expr,
74-
node.getAlias()));
68+
return Collections.singletonList(
69+
DSL.named(unqualifiedNameIfFieldOnly(node, context), expr, node.getAlias()));
7570
}
7671

7772
/**
@@ -86,32 +81,32 @@ public List<NamedExpression> visitAlias(Alias node, AnalysisContext context) {
8681
* Project(Alias("name", expr, l), Alias("AVG(age)", aggExpr))<br>
8782
* Agg(Alias("AVG(age)", aggExpr), Alias("length(name)", groupExpr))<br>
8883
*/
89-
private Expression referenceIfSymbolDefined(Alias expr,
90-
AnalysisContext context) {
84+
private Expression referenceIfSymbolDefined(Alias expr, AnalysisContext context) {
9185
UnresolvedExpression delegatedExpr = expr.getDelegated();
9286

9387
// Pass named expression because expression like window function loses full name
9488
// (OVER clause) and thus depends on name in alias to be replaced correctly
9589
return optimizer.optimize(
9690
DSL.named(
97-
expr.getName(),
98-
delegatedExpr.accept(expressionAnalyzer, context),
99-
expr.getAlias()),
91+
expr.getName(), delegatedExpr.accept(expressionAnalyzer, context), expr.getAlias()),
10092
context);
10193
}
10294

10395
@Override
104-
public List<NamedExpression> visitAllFields(AllFields node,
105-
AnalysisContext context) {
96+
public List<NamedExpression> visitAllFields(AllFields node, AnalysisContext context) {
10697
TypeEnvironment environment = context.peek();
10798
Map<String, ExprType> lookupAllFields = environment.lookupAllFields(Namespace.FIELD_NAME);
108-
return lookupAllFields.entrySet().stream().map(entry -> DSL.named(entry.getKey(),
109-
new ReferenceExpression(entry.getKey(), entry.getValue()))).collect(Collectors.toList());
99+
return lookupAllFields.entrySet().stream()
100+
.map(
101+
entry ->
102+
DSL.named(
103+
entry.getKey(), new ReferenceExpression(entry.getKey(), entry.getValue())))
104+
.collect(Collectors.toList());
110105
}
111106

112107
@Override
113-
public List<NamedExpression> visitNestedAllTupleFields(NestedAllTupleFields node,
114-
AnalysisContext context) {
108+
public List<NamedExpression> visitNestedAllTupleFields(
109+
NestedAllTupleFields node, AnalysisContext context) {
115110
TypeEnvironment environment = context.peek();
116111
Map<String, ExprType> lookupAllTupleFields =
117112
environment.lookupAllTupleFields(Namespace.FIELD_NAME);
@@ -121,14 +116,15 @@ public List<NamedExpression> visitNestedAllTupleFields(NestedAllTupleFields node
121116
Pattern p = Pattern.compile(node.getPath() + "\\.[^\\.]+$");
122117
return lookupAllTupleFields.entrySet().stream()
123118
.filter(field -> p.matcher(field.getKey()).find())
124-
.map(entry -> {
125-
Expression nestedFunc = new Function(
126-
"nested",
127-
List.of(
128-
new QualifiedName(List.of(entry.getKey().split("\\."))))
129-
).accept(expressionAnalyzer, context);
130-
return DSL.named("nested(" + entry.getKey() + ")", nestedFunc);
131-
})
119+
.map(
120+
entry -> {
121+
Expression nestedFunc =
122+
new Function(
123+
"nested",
124+
List.of(new QualifiedName(List.of(entry.getKey().split("\\.")))))
125+
.accept(expressionAnalyzer, context);
126+
return DSL.named("nested(" + entry.getKey() + ")", nestedFunc);
127+
})
132128
.collect(Collectors.toList());
133129
}
134130

@@ -149,5 +145,4 @@ private String unqualifiedNameIfFieldOnly(Alias node, AnalysisContext context) {
149145
}
150146
return node.getName();
151147
}
152-
153148
}

0 commit comments

Comments
 (0)