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

Method convertArray

sup/analyzer.go:366–398  ·  view source on GitHub ↗
(sctx *super.Context, array *ast.Array, cast super.Type)

Source from the content-addressed store, hash-verified

364}
365
366func (a Analyzer) convertArray(sctx *super.Context, array *ast.Array, cast super.Type) (Value, error) {
367 vals := make([]Value, 0, len(array.Elements))
368 typ, err := arrayElemCast(cast)
369 if err != nil {
370 return nil, err
371 }
372 for _, elem := range array.Elements {
373 v, err := a.convertValue(sctx, elem, typ)
374 if err != nil {
375 return nil, err
376 }
377 vals = append(vals, v)
378 }
379 if cast != nil || len(vals) == 0 {
380 // We had a cast so we know any type mistmatches we have been
381 // caught below...
382 if cast == nil {
383 cast = sctx.LookupTypeArray(super.TypeNull)
384 }
385 return &Array{
386 Type: cast,
387 Elements: vals,
388 }, nil
389 }
390 elems, inner, err := a.normalizeElems(sctx, vals)
391 if err != nil {
392 return nil, err
393 }
394 return &Array{
395 Type: sctx.LookupTypeArray(inner),
396 Elements: elems,
397 }, nil
398}
399
400func (a Analyzer) normalizeElems(sctx *super.Context, vals []Value) ([]Value, super.Type, error) {
401 types := make([]super.Type, len(vals))

Callers 1

convertAnyMethod · 0.95

Calls 4

convertValueMethod · 0.95
normalizeElemsMethod · 0.95
arrayElemCastFunction · 0.85
LookupTypeArrayMethod · 0.80

Tested by

no test coverage detected