MCPcopy Index your code
hub / github.com/rilldata/rill / parseModel

Method parseModel

runtime/parser/parse_model.go:83–283  ·  view source on GitHub ↗

parseModel parses a model definition and adds the resulting resource to p.Resources.

(ctx context.Context, node *Node)

Source from the content-addressed store, hash-verified

81
82// parseModel parses a model definition and adds the resulting resource to p.Resources.
83func (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 {

Callers 2

parseNodeMethod · 0.95
parseSourceMethod · 0.95

Calls 12

decodeNodeYAMLMethod · 0.95
parseScheduleYAMLMethod · 0.95
inferSQLRefsMethod · 0.95
defaultOLAPConnectorMethod · 0.95
parseDataYAMLMethod · 0.95
parseModelTestMethod · 0.95
insertResourceMethod · 0.95
parseChangeModeYAMLFunction · 0.85
parseDurationFunction · 0.85
NormalizedMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected