This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement, add the field type conflict check in semantic check (#470)
* Enhancement, add the field type conflict check in semantic check
- Loading branch information
Showing
18 changed files
with
627 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ src/site-server/node_modules | |
/out/ | ||
.gradle/ | ||
build/ | ||
gen/ | ||
*.tokens | ||
|
||
# various IDE files | ||
.vscode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...ain/java/com/amazon/opendistroforelasticsearch/sql/antlr/semantic/scope/TypeSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.sql.antlr.semantic.scope; | ||
|
||
import com.amazon.opendistroforelasticsearch.sql.antlr.semantic.SemanticAnalysisException; | ||
import com.amazon.opendistroforelasticsearch.sql.antlr.semantic.types.Type; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* The TypeSupplier is construct by the symbolName and symbolType. | ||
* The TypeSupplier implement the {@link Supplier<Type>} interface to provide the {@link Type}. | ||
* The TypeSupplier maintain types to track different {@link Type} definition for the same symbolName. | ||
*/ | ||
public class TypeSupplier implements Supplier<Type> { | ||
private final String symbolName; | ||
private final Type symbolType; | ||
private final Set<Type> types; | ||
|
||
public TypeSupplier(String symbolName, Type symbolType) { | ||
this.symbolName = symbolName; | ||
this.symbolType = symbolType; | ||
this.types = new HashSet<>(); | ||
this.types.add(symbolType); | ||
} | ||
|
||
public TypeSupplier add(Type type) { | ||
types.add(type); | ||
return this; | ||
} | ||
|
||
/** | ||
* Get the {@link Type} | ||
* Throw {@link SemanticAnalysisException} if conflict found. | ||
* Currently, if the two types not equal, they are treated as conflicting. | ||
*/ | ||
@Override | ||
public Type get() { | ||
if (types.size() > 1) { | ||
throw new SemanticAnalysisException( | ||
String.format("Field [%s] have conflict type [%s]", symbolName, types)); | ||
} else { | ||
return symbolType; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.