Skip to content

Commit

Permalink
Refactor the Alias node to avoid ambiguity
Browse files Browse the repository at this point in the history
Signed-off-by: Lantao Jin <[email protected]>
  • Loading branch information
LantaoJin committed Dec 9, 2024
1 parent b9cf14e commit c54551b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) {
return nodeVisitor.visitAlias(this, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>()),
Option.empty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

Expand Down

0 comments on commit c54551b

Please sign in to comment.