Repository: pingcap/tidb
File: pkg/executor/importer/import.go (Go)

Code before:
			}
			optionMap[opt.Name] = val
		} else {
			optionMap[opt.Name] = nil
		}
	}
	p.Parameters = &ImportParameters{
		ColumnsAndVars: columnsAndVars,
		SetClause:      setClause,
		FileLocation:   redactURL,
		Format:         p.Format,
		Options:        optionMap,
	}
	return nil
}

func (e *LoadDataController) tableVisCols2FieldMappings() ([]*FieldMapping, []string) {
	tableCols := e.Table.VisibleCols()
	mappings := make([]*FieldMapping, 0, len(tableCols))
	names := make([]string, 0, len(tableCols))
	for _, v := range tableCols {
		// Data for generated column is generated from the other rows rather than from the parsed data.
		fieldMapping := &FieldMapping{
			Column: v,
		}
		if model.IsInternalColumn(v.ColumnInfo.Name) {
			continue
		}
		mappings = append(mappings, fieldMapping)
		names = append(names, v.Name.O)
	}
	return mappings, names
}

// initFieldMappings make a field mapping slice to implicitly map input field to table column or user defined variable
// the slice's order is the same as the order of the input fields.
// Returns a slice of same ordered column names without user defined variable names.
func (e *LoadDataController) initFieldMappings() []string {
	columns := make([]string, 0, len(e.ColumnsAndUserVars)+len(e.ColumnAssignments))
	tableCols := e.Table.VisibleCols()

	if len(e.ColumnsAndUserVars) == 0 {
		e.FieldMappings, columns = e.tableVisCols2FieldMappings()

		return columns
	}

	var column *table.Column

	for _, v := range e.ColumnsAndUserVars {
		if v.ColumnName != nil {

Review comment (suggestion):
How about using the same logic as:

https://github.com/pingcap/tidb/blob/b443e38f910ec866ed93d86219a509c19fbffcb4/pkg/planner/core/logical_plan_builder.go#L4642-L4645

We should see these columns by default when a table is not an active-active or softdelete table.

Code after:
			}
			optionMap[opt.Name] = val
		} else {
			optionMap[opt.Name] = nil
		}
	}
	p.Parameters = &ImportParameters{
		ColumnsAndVars: columnsAndVars,
		SetClause:      setClause,
		FileLocation:   redactURL,
		Format:         p.Format,
		Options:        optionMap,
	}
	return nil
}

func (e *LoadDataController) tableVisCols2FieldMappings() ([]*FieldMapping, []string) {
	tableCols := e.Table.VisibleCols()
	mappings := make([]*FieldMapping, 0, len(tableCols))
	names := make([]string, 0, len(tableCols))
	tableInfo := e.Table.Meta()
	for _, v := range tableCols {
		// When we're using soft delete or active-active table, there are some extra hidden columns
		// like _tidb_origin_ts, _tidb_soft_delete_time, if user is not explicitly specifying them,
		// load data should ignore them.
		col := v.ColumnInfo
		if (tableInfo.SoftdeleteInfo != nil && col.Name.L == model.ExtraSoftDeleteTimeName.L) ||
			(tableInfo.IsActiveActive && col.Name.L == model.ExtraOriginTSName.L) {
			continue
		}

		// Data for generated column is generated from the other rows rather than from the parsed data.
		fieldMapping := &FieldMapping{
			Column: v,
		}
		mappings = append(mappings, fieldMapping)
		names = append(names, v.Name.O)
	}
	return mappings, names
}

// initFieldMappings make a field mapping slice to implicitly map input field to table column or user defined variable
// the slice's order is the same as the order of the input fields.
// Returns a slice of same ordered column names without user defined variable names.
func (e *LoadDataController) initFieldMappings() []string {
	columns := make([]string, 0, len(e.ColumnsAndUserVars)+len(e.ColumnAssignments))
	tableCols := e.Table.VisibleCols()

	if len(e.ColumnsAndUserVars) == 0 {
		e.FieldMappings, columns = e.tableVisCols2FieldMappings()