decodeNodeYAML decodes a Node into a YAML struct. If knownFields is true, it will return an error if the YAML contains unknown fields. It applies defaults from rill.yaml, then the YAML, then the YAML's environment-specific overrides, and finally the SQL annotations. If an error is returned, it will
(node *Node, knownFields bool, dst any)
| 329 | // It applies defaults from rill.yaml, then the YAML, then the YAML's environment-specific overrides, and finally the SQL annotations. |
| 330 | // If an error is returned, it will be a pathError associated with the node. |
| 331 | func (p *Parser) decodeNodeYAML(node *Node, knownFields bool, dst any) error { |
| 332 | // Apply defaults from rill.yaml |
| 333 | if p.RillYAML != nil { |
| 334 | defaults := p.RillYAML.Defaults[node.Kind] |
| 335 | if !defaults.IsZero() { |
| 336 | if err := defaults.Decode(dst); err != nil { |
| 337 | return pathError{path: node.YAMLPath, err: fmt.Errorf("failed applying defaults from rill.yaml: %w", err)} |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | // Apply YAML |
| 343 | if node.YAML != nil { |
| 344 | var err error |
| 345 | if knownFields { |
| 346 | // Using node.YAMLRaw instead of node.YAML because we need to set KnownFields for metrics views |
| 347 | dec := yaml.NewDecoder(strings.NewReader(node.YAMLRaw)) |
| 348 | dec.KnownFields(true) |
| 349 | err = dec.Decode(dst) |
| 350 | } else { |
| 351 | err = node.YAML.Decode(dst) |
| 352 | } |
| 353 | if err != nil { |
| 354 | return pathError{path: node.YAMLPath, err: newYAMLError(err)} |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | // Override YAML config with SQL annotations |
| 359 | if len(node.SQLAnnotations) > 0 { |
| 360 | err := mapstructureUnmarshal(node.SQLAnnotations, dst) |
| 361 | if err != nil { |
| 362 | return pathError{path: node.SQLPath, err: fmt.Errorf("invalid SQL annotations: %w", err)} |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | // Apply environment-specific overrides |
| 367 | if node.YAMLOverride != nil { |
| 368 | err := node.YAMLOverride.Decode(dst) |
| 369 | if err != nil { |
| 370 | return pathError{path: node.YAMLPath, err: newYAMLError(err)} |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | return nil |
| 375 | } |
| 376 | |
| 377 | // parseYAMLRefs parses a list of YAML nodes into a list of ResourceNames. |
| 378 | // It's used to parse the "refs" field in baseConfig. |
no test coverage detected