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.
Support select fields and alias in new query engine (#636)
* Change grammar * Add UT * Change grammar and add UT for field alias * Support alias by named expression * Add UT * Add javadoc * Make query field required after test * Change java doc * Fix comparison test data type issue * Fix broken UT * Fix jacoco coverage * Fix broken UTs * Fix PPL ast builder * Add doctest * Fix broken legacy IT * Fix jacoco * Fix all IT and preserve original name with alias * Fix remove command failure * Fix remove command failure * Fix doctest * Fix broken UT * Fix broken UT * Revert to make Alias optional for PPL * Prepare PR * Prepare PR * Prepare PR * Dont remove single quotes for column and alias name
- Loading branch information
Showing
49 changed files
with
759 additions
and
175 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
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
58 changes: 58 additions & 0 deletions
58
core/src/main/java/com/amazon/opendistroforelasticsearch/sql/ast/expression/Alias.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,58 @@ | ||
/* | ||
* Copyright 2020 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.ast.expression; | ||
|
||
import com.amazon.opendistroforelasticsearch.sql.ast.AbstractNodeVisitor; | ||
import lombok.AllArgsConstructor; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
|
||
/** | ||
* Alias abstraction that associate an unnamed expression with a name and an optional alias. | ||
* The name and alias information preserved is useful for semantic analysis and response | ||
* formatting eventually. This can avoid restoring the info in toString() method which is | ||
* inaccurate because original info is already lost. | ||
*/ | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(callSuper = false) | ||
@Getter | ||
@RequiredArgsConstructor | ||
@ToString | ||
public class Alias extends UnresolvedExpression { | ||
|
||
/** | ||
* Original field name. | ||
*/ | ||
private final String name; | ||
|
||
/** | ||
* Expression aliased. | ||
*/ | ||
private final UnresolvedExpression delegated; | ||
|
||
/** | ||
* Optional field alias. | ||
*/ | ||
private String alias; | ||
|
||
@Override | ||
public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) { | ||
return nodeVisitor.visitAlias(this, context); | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
core/src/main/java/com/amazon/opendistroforelasticsearch/sql/expression/NamedExpression.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,72 @@ | ||
/* | ||
* Copyright 2020 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.expression; | ||
|
||
import com.amazon.opendistroforelasticsearch.sql.data.model.ExprValue; | ||
import com.amazon.opendistroforelasticsearch.sql.data.type.ExprType; | ||
import com.amazon.opendistroforelasticsearch.sql.expression.env.Environment; | ||
import com.google.common.base.Strings; | ||
import lombok.AllArgsConstructor; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
|
||
/** | ||
* Named expression that represents expression with name. | ||
* Please see more details in associated unresolved expression operator | ||
* {@link com.amazon.opendistroforelasticsearch.sql.ast.expression.Alias}. | ||
*/ | ||
@AllArgsConstructor | ||
@EqualsAndHashCode | ||
@RequiredArgsConstructor | ||
@ToString | ||
public class NamedExpression implements Expression { | ||
|
||
/** | ||
* Expression name. | ||
*/ | ||
private final String name; | ||
|
||
/** | ||
* Expression that being named. | ||
*/ | ||
private final Expression delegated; | ||
|
||
/** | ||
* Optional alias. | ||
*/ | ||
private String alias; | ||
|
||
@Override | ||
public ExprValue valueOf(Environment<Expression, ExprValue> valueEnv) { | ||
return delegated.valueOf(valueEnv); | ||
} | ||
|
||
@Override | ||
public ExprType type() { | ||
return delegated.type(); | ||
} | ||
|
||
/** | ||
* Get expression name using name or its alias (if it's present). | ||
* @return expression name | ||
*/ | ||
public String getName() { | ||
return Strings.isNullOrEmpty(alias) ? name : alias; | ||
} | ||
|
||
} |
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.