Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the Alias node to avoid ambiguity #975

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading