// resolveGeneratedColumns resolves generated columns with their generation
// expressions respectively. onDups indicates which columns are in on-duplicate list.
resolveGeneratedColumns resolves generated columns with their generation
expressions respectively. onDups indicates which columns are in on-duplicate list.
// resolveGeneratedColumns resolves generated columns with their generation // expressions respectively . onDups indicates which columns are in on - duplicate list .
func (b *PlanBuilder) resolveGeneratedColumns(ctx context.Context, columns []*table.Column, onDups map[string]struct{}, mockPlan LogicalPlan) (igc InsertGeneratedColumns, err error) {
	for _, column := range columns {
		if !column.IsGenerated() {
			continue
		}
		columnName := &ast.ColumnName{Name: column.Name}
		columnName.SetText(column.Name.O)
		idx, err := expression.FindFieldName(mockPlan.OutputNames(), columnName)
		if err != nil {
			return igc, err
		}
		colExpr := mockPlan.Schema().Columns[idx]
		expr, _, err := b.rewrite(ctx, column.GeneratedExpr, mockPlan, nil, true)
		if err != nil {
			return igc, err
		}
		igc.Columns = append(igc.Columns, columnName)
		igc.Exprs = append(igc.Exprs, expr)
		if onDups == nil {
			continue
		}
		for dep := range column.Dependences {
			if _, ok := onDups[dep]; ok {
				assign := &expression.Assignment{Col: colExpr, ColName: column.Name, Expr: expr}
				igc.OnDuplicates = append(igc.OnDuplicates, assign)
				break
			}
		}
	}
	return igc, nil
}
func ( b * PlanBuilder ) resolveGeneratedColumns ( ctx context . Context , columns [ ] * table . Column , onDups map [ string ] struct { } , mockPlan LogicalPlan ) ( igc InsertGeneratedColumns , err error ) { for _ , column := range columns { if ! column . IsGenerated ( ) { continue } columnName := & ast . ColumnName { Name : column . Name } columnName . SetText ( column . Name . O ) idx , err := expression . FindFieldName ( mockPlan . OutputNames ( ) , columnName ) if err != nil { return igc , err } colExpr := mockPlan . Schema ( ) . Columns [ idx ] expr , _ , err := b . rewrite ( ctx , column . GeneratedExpr , mockPlan , nil , true ) if err != nil { return igc , err } igc . Columns = append ( igc . Columns , columnName ) igc . Exprs = append ( igc . Exprs , expr ) if onDups == nil { continue } for dep := range column . Dependences { if _ , ok := onDups [ dep ] ; ok { assign := & expression . Assignment { Col : colExpr , ColName : column . Name , Expr : expr } igc . OnDuplicates = append ( igc . OnDuplicates , assign ) break } } } return igc , nil }
resolveGeneratedColumns resolves generated columns with their generation
expressions respectively.
resolveGeneratedColumns resolves generated columns with their generation expressions respectively .