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

Function metadataValue

csup/metadata.go:242–288  ·  view source on GitHub ↗
(cctx *Context, sctx *super.Context, b *scode.Builder, id ID, projection field.Projection)

Source from the content-addressed store, hash-verified

240}
241
242func metadataValue(cctx *Context, sctx *super.Context, b *scode.Builder, id ID, projection field.Projection) super.Type {
243 m := cctx.Lookup(id)
244 switch m := under(cctx, m).(type) {
245 case *Dict:
246 return metadataValue(cctx, sctx, b, m.Values, projection)
247 case *Record:
248 var fields []super.Field
249 b.BeginContainer()
250 if len(projection) == 0 {
251 for _, f := range m.Fields {
252 typ := metadataValue(cctx, sctx, b, f.Values, nil)
253 fields = append(fields, super.NewFieldWithOpt(f.Name, typ, f.Opt))
254 }
255 } else {
256 for _, node := range projection {
257 if k := indexOfField(node.Name, m.Fields); k >= 0 {
258 typ := metadataValue(cctx, sctx, b, m.Fields[k].Values, node.Proj)
259 fields = append(fields, super.NewFieldWithOpt(node.Name, typ, m.Fields[k].Opt))
260 }
261 }
262 }
263 b.EndContainer()
264 return sctx.MustLookupTypeRecord(fields)
265 case *Primitive:
266 min, max := super.Null, super.Null
267 if m.Min != nil {
268 min = *m.Min
269 }
270 if m.Max != nil {
271 max = *m.Max
272 }
273 return metadataLeaf(sctx, b, min, max)
274 case *Int:
275 return metadataLeaf(sctx, b, super.NewInt(m.Typ, m.Min), super.NewInt(m.Typ, m.Max))
276 case *Uint:
277 return metadataLeaf(sctx, b, super.NewUint(m.Typ, m.Min), super.NewUint(m.Typ, m.Max))
278 case *Float:
279 return metadataLeaf(sctx, b, super.NewFloat(m.Typ, m.Min), super.NewFloat(m.Typ, m.Max))
280 case *Bytes:
281 return metadataLeaf(sctx, b, super.NewValue(m.Typ, m.Min), super.NewValue(m.Typ, m.Max))
282 case *Const:
283 return metadataLeaf(sctx, b, m.Value, m.Value)
284 default:
285 b.Append(nil)
286 return super.TypeNull
287 }
288}
289
290func metadataLeaf(sctx *super.Context, b *scode.Builder, min, max super.Value) super.Type {
291 b.BeginContainer()

Callers 1

ProjectMetadataMethod · 0.85

Calls 13

NewFieldWithOptFunction · 0.92
NewIntFunction · 0.92
NewUintFunction · 0.92
NewFloatFunction · 0.92
NewValueFunction · 0.92
underFunction · 0.85
metadataLeafFunction · 0.85
BeginContainerMethod · 0.80
EndContainerMethod · 0.80
MustLookupTypeRecordMethod · 0.80
indexOfFieldFunction · 0.70
LookupMethod · 0.65

Tested by

no test coverage detected