parseModel parses a model definition and adds the resulting resource to p.Resources.
(ctx context.Context, node *Node)
| 81 | |
| 82 | // parseModel parses a model definition and adds the resulting resource to p.Resources. |
| 83 | func (p *Parser) parseModel(ctx context.Context, node *Node) error { |
| 84 | // Parse YAML |
| 85 | tmp := &ModelYAML{} |
| 86 | err := p.decodeNodeYAML(node, false, tmp) |
| 87 | if err != nil { |
| 88 | return err |
| 89 | } |
| 90 | |
| 91 | // Parse the change mode |
| 92 | changeMode, err := parseChangeModeYAML(tmp.ChangeMode) |
| 93 | if err != nil { |
| 94 | return err |
| 95 | } |
| 96 | |
| 97 | // Parse refresh schedule |
| 98 | schedule, err := p.parseScheduleYAML(tmp.Refresh, true) |
| 99 | if err != nil { |
| 100 | return err |
| 101 | } |
| 102 | |
| 103 | // Parse timeout |
| 104 | var timeout time.Duration |
| 105 | if tmp.Timeout != "" { |
| 106 | timeout, err = parseDuration(tmp.Timeout) |
| 107 | if err != nil { |
| 108 | return err |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // Build input details |
| 113 | inputConnector := node.Connector |
| 114 | inputProps := tmp.InputProperties |
| 115 | if inputProps == nil { |
| 116 | inputProps = map[string]any{} |
| 117 | } |
| 118 | node.Refs = append(node.Refs, ResourceName{Kind: ResourceKindConnector, Name: inputConnector}) |
| 119 | |
| 120 | // Special handling for adding SQL to the input properties |
| 121 | if sql := strings.TrimSpace(node.SQL); sql != "" { |
| 122 | refs, err := p.inferSQLRefs(node) |
| 123 | if err != nil { |
| 124 | return err |
| 125 | } |
| 126 | node.Refs = append(node.Refs, refs...) |
| 127 | |
| 128 | inputProps["sql"] = sql |
| 129 | } |
| 130 | |
| 131 | // special handling to mark model as updated when local file changes |
| 132 | if inputConnector == "local_file" { |
| 133 | err = p.trackResourceNamesForDataPaths(ctx, ResourceName{Kind: ResourceKindModel, Name: node.Name}.Normalized(), inputProps) |
| 134 | if err != nil { |
| 135 | return err |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | inputPropsPB, err := structpb.NewStruct(inputProps) |
| 140 | if err != nil { |
no test coverage detected