Skip to content

Commit 5381a6f

Browse files
authored
(#1506) Remove reservedSymbolTable and replace with HIDDEN_FIELD_NAME (#1936)
* (#1506) Remove reservedSymbolTable and replace with HIDDEN_FIELD_NAME (#323) * #1506: Remove reservedSymbolTable and use HIDDEN_FIELD_NAME instead Signed-off-by: acarbonetto <[email protected]> * #1506: Remove reservedSymbolTable and use HIDDEN_FIELD_NAME instead Signed-off-by: acarbonetto <[email protected]> * #1506: Fix checkstyle errors Signed-off-by: acarbonetto <[email protected]> --------- Signed-off-by: acarbonetto <[email protected]> * #1506: spotless apply Signed-off-by: acarbonetto <[email protected]> --------- Signed-off-by: acarbonetto <[email protected]>
1 parent c99549a commit 5381a6f

File tree

5 files changed

+7
-14
lines changed

5 files changed

+7
-14
lines changed

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

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

166166
// Put index name or its alias in index namespace on type environment so qualifier
167167
// can be removed when analyzing qualified name. The value (expr type) here doesn't matter.
@@ -215,7 +215,7 @@ public LogicalPlan visitTableFunction(TableFunction node, AnalysisContext contex
215215
table.getFieldTypes().forEach((k, v) -> curEnv.define(new Symbol(Namespace.FIELD_NAME, k), v));
216216
table
217217
.getReservedFieldTypes()
218-
.forEach((k, v) -> curEnv.addReservedWord(new Symbol(Namespace.FIELD_NAME, k), v));
218+
.forEach((k, v) -> curEnv.define(new Symbol(Namespace.HIDDEN_FIELD_NAME, k), v));
219219
curEnv.define(
220220
new Symbol(
221221
Namespace.INDEX_NAME, dataSourceSchemaIdentifierNameResolver.getIdentifierName()),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public Expression visitQualifiedName(QualifiedName node, AnalysisContext context
378378
typeEnv != null;
379379
typeEnv = typeEnv.getParent()) {
380380
Optional<ExprType> exprType =
381-
typeEnv.getReservedSymbolTable().lookup(new Symbol(Namespace.FIELD_NAME, part));
381+
Optional.ofNullable(typeEnv.lookupAllFields(Namespace.HIDDEN_FIELD_NAME).get(part));
382382
if (exprType.isPresent()) {
383383
return visitMetadata(
384384
qualifierAnalyzer.unqualified(node), (ExprCoreType) exprType.get(), context);

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public class TypeEnvironment implements Environment<Symbol, ExprType> {
2525
@Getter private final TypeEnvironment parent;
2626
private final SymbolTable symbolTable;
2727

28-
@Getter private final SymbolTable reservedSymbolTable;
29-
3028
/**
3129
* Constructor with empty symbol tables.
3230
*
@@ -35,7 +33,6 @@ public class TypeEnvironment implements Environment<Symbol, ExprType> {
3533
public TypeEnvironment(TypeEnvironment parent) {
3634
this.parent = parent;
3735
this.symbolTable = new SymbolTable();
38-
this.reservedSymbolTable = new SymbolTable();
3936
}
4037

4138
/**
@@ -47,7 +44,6 @@ public TypeEnvironment(TypeEnvironment parent) {
4744
public TypeEnvironment(TypeEnvironment parent, SymbolTable symbolTable) {
4845
this.parent = parent;
4946
this.symbolTable = symbolTable;
50-
this.reservedSymbolTable = new SymbolTable();
5147
}
5248

5349
/**
@@ -123,8 +119,4 @@ public void remove(ReferenceExpression ref) {
123119
public void clearAllFields() {
124120
lookupAllFields(FIELD_NAME).keySet().forEach(v -> remove(new Symbol(Namespace.FIELD_NAME, v)));
125121
}
126-
127-
public void addReservedWord(Symbol symbol, ExprType type) {
128-
reservedSymbolTable.store(symbol, type);
129-
}
130122
}

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
@@ -9,6 +9,7 @@
99
public enum Namespace {
1010
INDEX_NAME("Index"),
1111
FIELD_NAME("Field"),
12+
HIDDEN_FIELD_NAME("HiddenField"),
1213
FUNCTION_NAME("Function");
1314

1415
private final String name;

core/src/test/java/org/opensearch/sql/analysis/ExpressionAnalyzerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,13 @@ public void qualified_name_with_qualifier() {
216216
public void qualified_name_with_reserved_symbol() {
217217
analysisContext.push();
218218

219-
analysisContext.peek().addReservedWord(new Symbol(Namespace.FIELD_NAME, "_reserved"), STRING);
220-
analysisContext.peek().addReservedWord(new Symbol(Namespace.FIELD_NAME, "_priority"), FLOAT);
219+
analysisContext.peek().define(new Symbol(Namespace.HIDDEN_FIELD_NAME, "_reserved"), STRING);
220+
analysisContext.peek().define(new Symbol(Namespace.HIDDEN_FIELD_NAME, "_priority"), FLOAT);
221221
analysisContext.peek().define(new Symbol(Namespace.INDEX_NAME, "index_alias"), STRUCT);
222222
assertAnalyzeEqual(DSL.ref("_priority", FLOAT), qualifiedName("_priority"));
223223
assertAnalyzeEqual(DSL.ref("_reserved", STRING), qualifiedName("index_alias", "_reserved"));
224224

225-
// reserved fields take priority over symbol table
225+
// cannot replace an existing field type
226226
analysisContext.peek().define(new Symbol(Namespace.FIELD_NAME, "_reserved"), LONG);
227227
assertAnalyzeEqual(DSL.ref("_reserved", STRING), qualifiedName("index_alias", "_reserved"));
228228

0 commit comments

Comments
 (0)