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

Method parseDataYAML

runtime/parser/parse_partial_data.go:30–155  ·  view source on GitHub ↗

parseDataYAML parses a data resolver and its properties from a DataYAML. The contextualConnector argument is optional; if provided and the resolver supports a connector, it becomes the default connector for the resolver. It returns the resolver name, its properties, and refs found in the resolver pr

(paths []string, raw *DataYAML, contextualConnector string)

Source from the content-addressed store, hash-verified

28// The contextualConnector argument is optional; if provided and the resolver supports a connector, it becomes the default connector for the resolver.
29// It returns the resolver name, its properties, and refs found in the resolver props.
30func (p *Parser) parseDataYAML(paths []string, raw *DataYAML, contextualConnector string) (string, *structpb.Struct, []ResourceName, error) {
31 // If there are any unused fields put it in compiler warnings
32 if len(raw.UnusedFields) > 0 {
33 for _, path := range paths {
34 p.addParseWarning(path, fmt.Sprintf("undefined fields in resolver properties: %q, will be ignored", maps.Keys(raw.UnusedFields)))
35 }
36 }
37
38 // Parse the resolver and its properties
39 var count int
40 var resolver string
41 var refs []ResourceName
42 resolverProps := make(map[string]any)
43
44 // Handle basic SQL resolver
45 if raw.SQL != "" {
46 count++
47 resolver = "sql"
48 resolverProps["sql"] = raw.SQL
49 if raw.Connector != "" {
50 resolverProps["connector"] = raw.Connector
51 refs = append(refs, ResourceName{Kind: ResourceKindConnector, Name: raw.Connector})
52 } else if contextualConnector != "" {
53 resolverProps["connector"] = contextualConnector
54 refs = append(refs, ResourceName{Kind: ResourceKindConnector, Name: contextualConnector})
55 }
56 }
57
58 // Handle metrics SQL resolver
59 if raw.MetricsSQL != "" {
60 count++
61 resolver = "metrics_sql"
62 resolverProps["sql"] = raw.MetricsSQL
63 }
64
65 if len(raw.Metrics) > 0 {
66 count++
67 resolver = "metrics"
68 resolverProps = raw.Metrics
69 // get metrics view to add refs
70 mvName, ok := raw.Metrics["metrics_view"].(string)
71 if !ok {
72 return "", nil, nil, fmt.Errorf("metrics resolver requires a metrics_view to be specified")
73 }
74 refs = append(refs, ResourceName{Kind: ResourceKindMetricsView, Name: mvName})
75 }
76
77 // Handle API resolver
78 if raw.API != "" {
79 count++
80 resolver = "api"
81 resolverProps["api"] = raw.API
82 refs = append(refs, ResourceName{Kind: ResourceKindAPI, Name: raw.API})
83 if raw.Args != nil {
84 resolverProps["args"] = raw.Args
85 }
86 }
87

Callers 5

parseReportMethod · 0.95
parseAlertMethod · 0.95
parseModelMethod · 0.95
parseModelTestMethod · 0.95
parseAPIMethod · 0.95

Calls 5

addParseWarningMethod · 0.95
ErrorfMethod · 0.65
IsZeroMethod · 0.45
DecodeMethod · 0.45
AsMapMethod · 0.45

Tested by

no test coverage detected