MCPcopy Create free account
hub / github.com/datasweet/datatable / join

Method join

join.go:246–352  ·  view source on GitHub ↗
(left, right *DataTable)

Source from the content-addressed store, hash-verified

244}
245
246func (j *joinImpl) join(left, right *DataTable) (*DataTable, error) {
247 if left == nil {
248 err := errors.New("left is nil datatable")
249 return nil, errors.Wrap(err, ErrNilDatatable.Error())
250 }
251 if right == nil {
252 err := errors.New("right is nil datatable")
253 return nil, errors.Wrap(err, ErrNilDatatable.Error())
254 }
255
256 clauses := [2]*joinClause{
257 &joinClause{
258 table: left,
259 mcols: j.mcols,
260 includeOnCols: true,
261 },
262 &joinClause{
263 table: right,
264 mcols: j.mcols,
265 },
266 }
267
268 // find on clauses
269 for _, o := range j.on {
270 if o.Table == left.Name() {
271 clauses[0].on = append(clauses[0].on, o.Field)
272 continue
273 }
274
275 if o.Table == right.Name() {
276 clauses[1].on = append(clauses[1].on, o.Field)
277 continue
278 }
279
280 if o.Table == "*" || len(o.Table) == 0 {
281 clauses[0].on = append(clauses[0].on, o.Field)
282 clauses[1].on = append(clauses[1].on, o.Field)
283 }
284 }
285
286 // create output
287 out := New(left.Name())
288 for _, clause := range clauses {
289 if err := clause.copyColumnsTo(out); err != nil {
290 return nil, err
291 }
292 }
293
294 // mode
295 var ref, join *joinClause
296 switch j.mode {
297 case innerJoin, leftJoin, outerJoin:
298 ref, join = clauses[0], clauses[1]
299 case rightJoin:
300 ref, join = clauses[1], clauses[0]
301 default:
302 err := errors.Errorf("unknown mode '%v'", j.mode)
303 return nil, errors.Wrap(err, ErrUnknownMode.Error())

Callers 1

ComputeMethod · 0.95

Calls 10

initHashTableMethod · 0.95
ExportHiddenFunction · 0.85
copyColumnsToMethod · 0.80
RowsMethod · 0.80
NewRowMethod · 0.80
NewFunction · 0.70
NameMethod · 0.65
GetMethod · 0.65
AppendMethod · 0.65
RowMethod · 0.45

Tested by

no test coverage detected