From 79b66ec4dad7709d1e11e257c19b6752fbc9ab73 Mon Sep 17 00:00:00 2001 From: Lantao Jin Date: Mon, 9 Dec 2024 12:37:43 +0800 Subject: [PATCH] Refactor the Alias node to avoid ambiguity Signed-off-by: Lantao Jin --- .../java/org/opensearch/sql/ast/expression/Alias.java | 10 +++------- .../opensearch/sql/ppl/CatalystExpressionVisitor.java | 2 +- .../sql/ppl/parser/AstExpressionBuilder.java | 3 +-- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/ppl-spark-integration/src/main/java/org/opensearch/sql/ast/expression/Alias.java b/ppl-spark-integration/src/main/java/org/opensearch/sql/ast/expression/Alias.java index 7b3078629..226ff7a8c 100644 --- a/ppl-spark-integration/src/main/java/org/opensearch/sql/ast/expression/Alias.java +++ b/ppl-spark-integration/src/main/java/org/opensearch/sql/ast/expression/Alias.java @@ -13,27 +13,23 @@ import org.opensearch.sql.ast.AbstractNodeVisitor; /** - * 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 + * Alias abstraction that associate an unnamed expression with a name. + * The name 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. */ + /** The name to be associated with the result of computing delegated expression. */ private final String name; /** Expression aliased. */ private final UnresolvedExpression delegated; - /** Optional field alias. */ - private String alias; - @Override public T accept(AbstractNodeVisitor nodeVisitor, C context) { return nodeVisitor.visitAlias(this, context); diff --git a/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/CatalystExpressionVisitor.java b/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/CatalystExpressionVisitor.java index 35ac7ed47..bc14ba9d4 100644 --- a/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/CatalystExpressionVisitor.java +++ b/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/CatalystExpressionVisitor.java @@ -257,7 +257,7 @@ public Expression visitAlias(Alias node, CatalystPlanContext context) { Expression arg = context.popNamedParseExpressions().get(); return context.getNamedParseExpressions().push( org.apache.spark.sql.catalyst.expressions.Alias$.MODULE$.apply(arg, - node.getAlias() != null ? node.getAlias() : node.getName(), + node.getName(), NamedExpression.newExprId(), seq(new java.util.ArrayList()), Option.empty(), diff --git a/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java b/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java index 0d5078fa8..1fe57d13e 100644 --- a/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java +++ b/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java @@ -383,8 +383,7 @@ public UnresolvedExpression visitBooleanLiteral(OpenSearchPPLParser.BooleanLiter public UnresolvedExpression visitBySpanClause(OpenSearchPPLParser.BySpanClauseContext ctx) { String name = ctx.spanClause().getText(); return ctx.alias != null - ? new Alias( - name, visit(ctx.spanClause()), StringUtils.unquoteIdentifier(ctx.alias.getText())) + ? new Alias(StringUtils.unquoteIdentifier(ctx.alias.getText()), visit(ctx.spanClause())) : new Alias(name, visit(ctx.spanClause())); }