MCPcopy Index your code
hub / github.com/pingcap/tidb / parserData2TableData

Method parserData2TableData

pkg/executor/importer/kv_encode.go:99–160  ·  view source on GitHub ↗

todo merge with code in load_data.go

(parserData []types.Datum, rowID int64)

Source from the content-addressed store, hash-verified

97
98// todo merge with code in load_data.go
99func (en *TableKVEncoder) parserData2TableData(parserData []types.Datum, rowID int64) ([]types.Datum, error) {
100 row := make([]types.Datum, 0, len(en.insertColumns))
101 setVar := func(name string, col *types.Datum) {
102 // User variable names are not case-sensitive
103 // https://dev.mysql.com/doc/refman/8.0/en/user-variables.html
104 name = strings.ToLower(name)
105 if col == nil || col.IsNull() {
106 en.SessionCtx.UnsetUserVar(name)
107 } else {
108 en.SessionCtx.SetUserVarVal(name, *col)
109 }
110 }
111
112 hasValue := make([]bool, len(en.Columns))
113 for i := range en.insertColumns {
114 offset := en.insertColumns[i].Offset
115 hasValue[offset] = true
116 }
117
118 for i := range en.fieldMappings {
119 col := en.fieldMappings[i].Column
120 if i >= len(parserData) {
121 if col == nil {
122 setVar(en.fieldMappings[i].UserVar.Name, nil)
123 continue
124 }
125
126 // If some columns is missing and their type is time and has not null flag, they should be set as current time.
127 if types.IsTypeTime(col.GetType()) && mysql.HasNotNullFlag(col.GetFlag()) {
128 row = append(row, types.NewTimeDatum(types.CurrentTime(col.GetType())))
129 continue
130 }
131
132 row = append(row, types.NewDatum(nil))
133 hasValue[col.Offset] = false
134 continue
135 }
136
137 if col == nil {
138 setVar(en.fieldMappings[i].UserVar.Name, &parserData[i])
139 continue
140 }
141
142 row = append(row, parserData[i])
143 }
144 for i := 0; i < len(en.columnAssignments); i++ {
145 // eval expression of `SET` clause
146 d, err := en.columnAssignments[i].Eval(en.SessionCtx.GetExprCtx().GetEvalCtx(), chunk.Row{})
147 if err != nil {
148 return nil, err
149 }
150 row = append(row, d)
151 }
152
153 // a new row buffer will be allocated in getRow
154 newRow, err := en.getRow(row, hasValue, rowID)
155 if err != nil {
156 return nil, err

Callers 1

EncodeMethod · 0.95

Calls 15

getRowMethod · 0.95
IsTypeTimeFunction · 0.92
HasNotNullFlagFunction · 0.92
NewTimeDatumFunction · 0.92
CurrentTimeFunction · 0.92
NewDatumFunction · 0.92
ToLowerMethod · 0.65
GetTypeMethod · 0.65
GetFlagMethod · 0.65
EvalMethod · 0.65
GetEvalCtxMethod · 0.65
GetExprCtxMethod · 0.65

Tested by

no test coverage detected