-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
planner: correct the generation of the field name #11324
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -591,12 +591,10 @@ func (b *PlanBuilder) buildSelection(p LogicalPlan, where ast.ExprNode, AggMappe | |
} | ||
|
||
// buildProjectionFieldNameFromColumns builds the field name, table name and database name when field expression is a column reference. | ||
func (b *PlanBuilder) buildProjectionFieldNameFromColumns(field *ast.SelectField, c *expression.Column) (colName, origColName, tblName, origTblName, dbName model.CIStr) { | ||
if astCol, ok := getInnerFromParenthesesAndUnaryPlus(field.Expr).(*ast.ColumnNameExpr); ok { | ||
origColName, tblName, dbName = astCol.Name.Name, astCol.Name.Table, astCol.Name.Schema | ||
} | ||
if field.AsName.L != "" { | ||
colName = field.AsName | ||
func (b *PlanBuilder) buildProjectionFieldNameFromColumns(origField *ast.SelectField, colNameField *ast.ColumnNameExpr, c *expression.Column) (colName, origColName, tblName, origTblName, dbName model.CIStr) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer not to change the ast's content 😂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will not be changed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, if there's no wild star. It's the original content. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But we can create a new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't need to change it for now. The logic of creating the field names will be rewritten in the following PRs. |
||
origColName, tblName, dbName = colNameField.Name.Name, colNameField.Name.Table, colNameField.Name.Schema | ||
if origField.AsName.L != "" { | ||
colName = origField.AsName | ||
} else { | ||
colName = origColName | ||
} | ||
|
@@ -677,9 +675,13 @@ func (b *PlanBuilder) buildProjectionFieldNameFromExpressions(field *ast.SelectF | |
// buildProjectionField builds the field object according to SelectField in projection. | ||
func (b *PlanBuilder) buildProjectionField(id, position int, field *ast.SelectField, expr expression.Expression) (*expression.Column, error) { | ||
var origTblName, tblName, origColName, colName, dbName model.CIStr | ||
if c, ok := expr.(*expression.Column); ok && !c.IsReferenced { | ||
innerNode := getInnerFromParenthesesAndUnaryPlus(field.Expr) | ||
col, isCol := expr.(*expression.Column) | ||
// Correlated column won't affect the final output names. So we can put it in any of the three logic block. | ||
// Don't put it into the first block just for simplifying the codes. | ||
if colNameField, ok := innerNode.(*ast.ColumnNameExpr); ok && isCol { | ||
// Field is a column reference. | ||
colName, origColName, tblName, origTblName, dbName = b.buildProjectionFieldNameFromColumns(field, c) | ||
colName, origColName, tblName, origTblName, dbName = b.buildProjectionFieldNameFromColumns(field, colNameField, col) | ||
} else if field.AsName.L != "" { | ||
// Field has alias. | ||
colName = field.AsName | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comptibility issue is separated work. #11323