Skip to content

Commit 3e46513

Browse files
authored
Merge branch '2.x' into backport2.x-1933
Signed-off-by: Mitchell Gale <[email protected]>
2 parents cf55f33 + 9f081ab commit 3e46513

File tree

98 files changed

+788
-1203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+788
-1203
lines changed

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ spotless {
8787
include 'core/src/main/java/org/opensearch/sql/DataSourceSchemaName.java',
8888
'core/src/test/java/org/opensearch/sql/data/**/*.java',
8989
'core/src/test/java/org/opensearch/sql/config/**/*.java',
90-
'core/src/test/java/org/opensearch/sql/analysis/**/*.java'
90+
'core/src/test/java/org/opensearch/sql/analysis/**/*.java',
91+
'core/src/main/java/org/opensearch/sql/planner/**/*.java',
92+
'core/src/main/java/org/opensearch/sql/storage/**/*.java',
93+
'core/src/main/java/org/opensearch/sql/utils/**/*.java',
94+
'core/src/main/java/org/opensearch/sql/monitor/**/*.java'
9195
exclude '**/build/**', '**/build-*/**'
9296
}
9397
importOrder()

core/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ repositories {
3333
mavenCentral()
3434
}
3535

36-
// Being ignored as a temporary measure before being removed in favour of
37-
// spotless https://github.com/opensearch-project/sql/issues/1101
3836
checkstyleTest.ignoreFailures = true
3937
checkstyleMain.ignoreFailures = true
4038

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ public LogicalPlan visitRelation(Relation node, AnalysisContext context) {
161161
dataSourceSchemaIdentifierNameResolver.getIdentifierName());
162162
}
163163
table.getFieldTypes().forEach((k, v) -> curEnv.define(new Symbol(Namespace.FIELD_NAME, k), v));
164-
table.getReservedFieldTypes().forEach(
165-
(k, v) -> curEnv.addReservedWord(new Symbol(Namespace.FIELD_NAME, k), v)
166-
);
164+
table
165+
.getReservedFieldTypes()
166+
.forEach((k, v) -> curEnv.define(new Symbol(Namespace.HIDDEN_FIELD_NAME, k), v));
167167

168168
// Put index name or its alias in index namespace on type environment so qualifier
169169
// can be removed when analyzing qualified name. The value (expr type) here doesn't matter.
@@ -207,12 +207,15 @@ public LogicalPlan visitTableFunction(TableFunction node, AnalysisContext contex
207207
TypeEnvironment curEnv = context.peek();
208208
Table table = tableFunctionImplementation.applyArguments();
209209
table.getFieldTypes().forEach((k, v) -> curEnv.define(new Symbol(Namespace.FIELD_NAME, k), v));
210-
table.getReservedFieldTypes().forEach(
211-
(k, v) -> curEnv.addReservedWord(new Symbol(Namespace.FIELD_NAME, k), v)
212-
);
213-
curEnv.define(new Symbol(Namespace.INDEX_NAME,
214-
dataSourceSchemaIdentifierNameResolver.getIdentifierName()), STRUCT);
215-
return new LogicalRelation(dataSourceSchemaIdentifierNameResolver.getIdentifierName(),
210+
table
211+
.getReservedFieldTypes()
212+
.forEach((k, v) -> curEnv.define(new Symbol(Namespace.HIDDEN_FIELD_NAME, k), v));
213+
curEnv.define(
214+
new Symbol(
215+
Namespace.INDEX_NAME, dataSourceSchemaIdentifierNameResolver.getIdentifierName()),
216+
STRUCT);
217+
return new LogicalRelation(
218+
dataSourceSchemaIdentifierNameResolver.getIdentifierName(),
216219
tableFunctionImplementation.applyArguments());
217220
}
218221

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,10 @@ public Expression visitQualifiedName(QualifiedName node, AnalysisContext context
371371
// check for reserved words in the identifier
372372
for (String part : node.getParts()) {
373373
for (TypeEnvironment typeEnv = context.peek();
374-
typeEnv != null;
375-
typeEnv = typeEnv.getParent()) {
376-
Optional<ExprType> exprType = typeEnv.getReservedSymbolTable().lookup(
377-
new Symbol(Namespace.FIELD_NAME, part));
374+
typeEnv != null;
375+
typeEnv = typeEnv.getParent()) {
376+
Optional<ExprType> exprType =
377+
Optional.ofNullable(typeEnv.lookupAllFields(Namespace.HIDDEN_FIELD_NAME).get(part));
378378
if (exprType.isPresent()) {
379379
return visitMetadata(
380380
qualifierAnalyzer.unqualified(node),

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ public class TypeEnvironment implements Environment<Symbol, ExprType> {
2929
private final TypeEnvironment parent;
3030
private final SymbolTable symbolTable;
3131

32-
@Getter
33-
private final SymbolTable reservedSymbolTable;
34-
3532
/**
3633
* Constructor with empty symbol tables.
3734
*
@@ -40,7 +37,6 @@ public class TypeEnvironment implements Environment<Symbol, ExprType> {
4037
public TypeEnvironment(TypeEnvironment parent) {
4138
this.parent = parent;
4239
this.symbolTable = new SymbolTable();
43-
this.reservedSymbolTable = new SymbolTable();
4440
}
4541

4642
/**
@@ -52,7 +48,6 @@ public TypeEnvironment(TypeEnvironment parent) {
5248
public TypeEnvironment(TypeEnvironment parent, SymbolTable symbolTable) {
5349
this.parent = parent;
5450
this.symbolTable = symbolTable;
55-
this.reservedSymbolTable = new SymbolTable();
5651
}
5752

5853
/**
@@ -133,8 +128,4 @@ public void clearAllFields() {
133128
lookupAllFields(FIELD_NAME).keySet().forEach(
134129
v -> remove(new Symbol(Namespace.FIELD_NAME, v)));
135130
}
136-
137-
public void addReservedWord(Symbol symbol, ExprType type) {
138-
reservedSymbolTable.store(symbol, type);
139-
}
140131
}

core/src/main/java/org/opensearch/sql/analysis/symbol/Namespace.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public enum Namespace {
1313

1414
INDEX_NAME("Index"),
1515
FIELD_NAME("Field"),
16+
HIDDEN_FIELD_NAME("HiddenField"),
1617
FUNCTION_NAME("Function");
1718

1819
private final String name;

core/src/main/java/org/opensearch/sql/monitor/AlwaysHealthyMonitor.java

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

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

9-
/**
10-
* Always healthy resource monitor.
11-
*/
8+
/** Always healthy resource monitor. */
129
public class AlwaysHealthyMonitor extends ResourceMonitor {
13-
public static final ResourceMonitor ALWAYS_HEALTHY_MONITOR =
14-
new AlwaysHealthyMonitor();
10+
public static final ResourceMonitor ALWAYS_HEALTHY_MONITOR = new AlwaysHealthyMonitor();
1511

16-
/**
17-
* always healthy.
18-
*/
12+
/** always healthy. */
1913
@Override
2014
public boolean isHealthy() {
2115
return true;

core/src/main/java/org/opensearch/sql/monitor/ResourceMonitor.java

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

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

98
/**
10-
* The abstract interface of ResourceMonitor.
11-
* When an fault is detected, the circuit breaker is open.
9+
* The abstract interface of ResourceMonitor. When an fault is detected, the circuit breaker is
10+
* open.
1211
*/
1312
public abstract class ResourceMonitor {
1413
/**

core/src/main/java/org/opensearch/sql/planner/DefaultImplementor.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@
4545

4646
/**
4747
* Default implementor for implementing logical to physical translation. "Default" here means all
48-
* logical operator will be translated to correspondent physical operator to pipeline operations
49-
* in post-processing style in memory.
50-
* Different storage can override methods here to optimize default pipelining operator, for example
51-
* a storage has the flexibility to override visitFilter and visitRelation to push down filtering
52-
* operation and return a single physical index scan operator.
48+
* logical operator will be translated to correspondent physical operator to pipeline operations in
49+
* post-processing style in memory. Different storage can override methods here to optimize default
50+
* pipelining operator, for example a storage has the flexibility to override visitFilter and
51+
* visitRelation to push down filtering operation and return a single physical index scan operator.
5352
*
54-
* @param <C> context type
53+
* @param <C> context type
5554
*/
5655
public class DefaultImplementor<C> extends LogicalPlanNodeVisitor<PhysicalPlan, C> {
5756

@@ -62,8 +61,7 @@ public PhysicalPlan visitRareTopN(LogicalRareTopN node, C context) {
6261
node.getCommandType(),
6362
node.getNoOfResults(),
6463
node.getFieldList(),
65-
node.getGroupByList()
66-
);
64+
node.getGroupByList());
6765
}
6866

6967
@Override
@@ -78,16 +76,14 @@ public PhysicalPlan visitDedupe(LogicalDedupe node, C context) {
7876

7977
@Override
8078
public PhysicalPlan visitProject(LogicalProject node, C context) {
81-
return new ProjectOperator(visitChild(node, context), node.getProjectList(),
82-
node.getNamedParseExpressions());
79+
return new ProjectOperator(
80+
visitChild(node, context), node.getProjectList(), node.getNamedParseExpressions());
8381
}
8482

8583
@Override
8684
public PhysicalPlan visitWindow(LogicalWindow node, C context) {
8785
return new WindowOperator(
88-
visitChild(node, context),
89-
node.getWindowFunction(),
90-
node.getWindowDefinition());
86+
visitChild(node, context), node.getWindowFunction(), node.getWindowDefinition());
9187
}
9288

9389
@Override
@@ -148,8 +144,9 @@ public PhysicalPlan visitTableWriteBuilder(TableWriteBuilder plan, C context) {
148144

149145
@Override
150146
public PhysicalPlan visitRelation(LogicalRelation node, C context) {
151-
throw new UnsupportedOperationException("Storage engine is responsible for "
152-
+ "implementing and optimizing logical plan with relation involved");
147+
throw new UnsupportedOperationException(
148+
"Storage engine is responsible for "
149+
+ "implementing and optimizing logical plan with relation involved");
153150
}
154151

155152
@Override

core/src/main/java/org/opensearch/sql/planner/PlanContext.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@
99
import lombok.Getter;
1010
import org.opensearch.sql.storage.split.Split;
1111

12-
/**
13-
* Plan context hold planning related information.
14-
*/
12+
/** Plan context hold planning related information. */
1513
public class PlanContext {
1614

17-
@Getter
18-
private final Optional<Split> split;
15+
@Getter private final Optional<Split> split;
1916

2017
public PlanContext(Split split) {
2118
this.split = Optional.of(split);

core/src/main/java/org/opensearch/sql/planner/PlanNode.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

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

98
import java.util.List;
109

11-
/**
12-
* The definition of Plan Node.
13-
*/
10+
/** The definition of Plan Node. */
1411
public interface PlanNode<T extends PlanNode> {
1512

1613
/**

core/src/main/java/org/opensearch/sql/planner/Planner.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

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

9-
108
import java.util.List;
119
import lombok.RequiredArgsConstructor;
1210
import org.opensearch.sql.planner.logical.LogicalPlan;
@@ -16,17 +14,15 @@
1614
import org.opensearch.sql.planner.physical.PhysicalPlan;
1715
import org.opensearch.sql.storage.Table;
1816

19-
/**
20-
* Planner that plans and chooses the optimal physical plan.
21-
*/
17+
/** Planner that plans and chooses the optimal physical plan. */
2218
@RequiredArgsConstructor
2319
public class Planner {
2420

2521
private final LogicalPlanOptimizer logicalOptimizer;
2622

2723
/**
28-
* Generate optimal physical plan for logical plan. If no table involved,
29-
* translate logical plan to physical by default implementor.
24+
* Generate optimal physical plan for logical plan. If no table involved, translate logical plan
25+
* to physical by default implementor.<br>
3026
* TODO: for now just delegate entire logical plan to storage engine.
3127
*
3228
* @param plan logical plan
@@ -37,28 +33,28 @@ public PhysicalPlan plan(LogicalPlan plan) {
3733
if (table == null) {
3834
return plan.accept(new DefaultImplementor<>(), null);
3935
}
40-
return table.implement(
41-
table.optimize(optimize(plan)));
36+
return table.implement(table.optimize(optimize(plan)));
4237
}
4338

4439
private Table findTable(LogicalPlan plan) {
45-
return plan.accept(new LogicalPlanNodeVisitor<Table, Object>() {
46-
47-
@Override
48-
public Table visitNode(LogicalPlan node, Object context) {
49-
List<LogicalPlan> children = node.getChild();
50-
if (children.isEmpty()) {
51-
return null;
52-
}
53-
return children.get(0).accept(this, context);
54-
}
55-
56-
@Override
57-
public Table visitRelation(LogicalRelation node, Object context) {
58-
return node.getTable();
59-
}
60-
61-
}, null);
40+
return plan.accept(
41+
new LogicalPlanNodeVisitor<Table, Object>() {
42+
43+
@Override
44+
public Table visitNode(LogicalPlan node, Object context) {
45+
List<LogicalPlan> children = node.getChild();
46+
if (children.isEmpty()) {
47+
return null;
48+
}
49+
return children.get(0).accept(this, context);
50+
}
51+
52+
@Override
53+
public Table visitRelation(LogicalRelation node, Object context) {
54+
return node.getTable();
55+
}
56+
},
57+
null);
6258
}
6359

6460
private LogicalPlan optimize(LogicalPlan plan) {

core/src/main/java/org/opensearch/sql/planner/SerializablePlan.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,37 @@
1010
/**
1111
* All subtypes of PhysicalPlan which needs to be serialized (in cursor, for pagination feature)
1212
* should follow one of the following options.
13+
*
1314
* <ul>
1415
* <li>Both:
15-
* <ul>
16-
* <li>Override both methods from {@link Externalizable}.</li>
17-
* <li>Define a public no-arg constructor.</li>
18-
* </ul>
19-
* </li>
20-
* <li>
21-
* Overwrite {@link #getPlanForSerialization} to return
22-
* another instance of {@link SerializablePlan}.
23-
* </li>
16+
* <ul>
17+
* <li>Override both methods from {@link Externalizable}.
18+
* <li>Define a public no-arg constructor.
19+
* </ul>
20+
* <li>Overwrite {@link #getPlanForSerialization} to return another instance of {@link
21+
* SerializablePlan}.
2422
* </ul>
2523
*/
2624
public interface SerializablePlan extends Externalizable {
2725

2826
/**
29-
* Override to return child or delegated plan, so parent plan should skip this one
30-
* for serialization, but it should try to serialize grandchild plan.
31-
* Imagine plan structure like this
27+
* Override to return child or delegated plan, so parent plan should skip this one for
28+
* serialization, but it should try to serialize grandchild plan. Imagine plan structure like this
29+
*
3230
* <pre>
3331
* A -> this
3432
* `- B -> child
3533
* `- C -> this
3634
* </pre>
37-
* In that case only plans A and C should be attempted to serialize.
38-
* It is needed to skip a `ResourceMonitorPlan` instance only, actually.
3935
*
40-
* <pre>{@code
41-
* * A.writeObject(B.getPlanForSerialization());
42-
* }</pre>
36+
* In that case only plans A and C should be attempted to serialize. It is needed to skip a
37+
* `ResourceMonitorPlan` instance only, actually.
38+
*
39+
* <pre>{@code
40+
* * A.writeObject(B.getPlanForSerialization());
41+
*
42+
* }</pre>
43+
*
4344
* @return Next plan for serialization.
4445
*/
4546
default SerializablePlan getPlanForSerialization() {

core/src/main/java/org/opensearch/sql/planner/logical/LogicalAD.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class LogicalAD extends LogicalPlan {
1818

1919
/**
2020
* Constructor of LogicalAD.
21+
*
2122
* @param child child logical plan
2223
* @param arguments arguments of the algorithm
2324
*/

0 commit comments

Comments
 (0)