MCPcopy Create free account
hub / github.com/brimdata/super / inlineRecordExprSpreads

Function inlineRecordExprSpreads

compiler/optimizer/optimizer.go:456–481  ·  view source on GitHub ↗

inlineRecordExprSpreads transforms "{...{a}}" to "{a}".

(v any)

Source from the content-addressed store, hash-verified

454
455// inlineRecordExprSpreads transforms "{...{a}}" to "{a}".
456func inlineRecordExprSpreads(v any) {
457 walkT(reflect.ValueOf(v), func(r *dag.RecordExpr) *dag.RecordExpr {
458 for i := range r.Elems {
459 s, ok := r.Elems[i].(*dag.Spread)
460 if !ok {
461 continue
462 }
463 r2, ok := s.Expr.(*dag.RecordExpr)
464 if !ok {
465 continue
466 }
467 r.Elems = slices.Concat(r.Elems[:i], r2.Elems, r.Elems[i+1:])
468 }
469 // dedupe elems from spreads
470 m := map[string]struct{}{}
471 for i := len(r.Elems) - 1; i >= 0; i-- {
472 if f, ok := r.Elems[i].(*dag.Field); ok {
473 if _, ok := m[f.Name]; ok {
474 r.Elems = slices.Delete(r.Elems, i, i+1)
475 }
476 m[f.Name] = struct{}{}
477 }
478 }
479 return r
480 })
481}
482
483func joinFilterPullup(seq dag.Seq) dag.Seq {
484 seq = mergeFilters(seq)

Callers 2

OptimizeMethod · 0.85
mergeValuesOpsFunction · 0.85

Calls 2

walkTFunction · 0.85
DeleteMethod · 0.65

Tested by

no test coverage detected