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

Method parseStem

runtime/parser/parse_node.go:101–325  ·  view source on GitHub ↗

parseStem parses a pair of YAML and SQL files with the same path stem (e.g. "/path/to/file.yaml" for "/path/to/file.sql"). Note that either of the YAML or SQL files may be empty (the paths arg will only contain non-nil paths).

(paths []string, ymlPath, yml, sqlPath, sql string)

Source from the content-addressed store, hash-verified

99// parseStem parses a pair of YAML and SQL files with the same path stem (e.g. "/path/to/file.yaml" for "/path/to/file.sql").
100// Note that either of the YAML or SQL files may be empty (the paths arg will only contain non-nil paths).
101func (p *Parser) parseStem(paths []string, ymlPath, yml, sqlPath, sql string) (*Node, error) {
102 // The rest of the function builds a Node from YAML and SQL info
103 res := &Node{Paths: paths}
104
105 // Parse YAML into commonYAML
106 var cfg *commonYAML
107 if ymlPath != "" {
108 var node yaml.Node
109 err := yaml.Unmarshal([]byte(yml), &node)
110 if err != nil {
111 return nil, pathError{path: ymlPath, err: newYAMLError(err)}
112 }
113 res.YAML = &node
114 res.YAMLRaw = yml
115 res.YAMLPath = ymlPath
116
117 err = node.Decode(&cfg)
118 if err != nil {
119 return nil, pathError{path: ymlPath, err: newYAMLError(err)}
120 }
121 }
122
123 // Handle YAML config
124 templatingEnabled := true
125 if cfg != nil {
126 // Copy EnvironmentOverridesOld to EnvironmentOverrides
127 for k, v := range cfg.EnvironmentOverridesOld { // nolint: gocritic // Using a pointer changes parser behavior
128 if cfg.EnvironmentOverrides == nil {
129 cfg.EnvironmentOverrides = make(map[string]yaml.Node)
130 }
131 cfg.EnvironmentOverrides[k] = v
132 }
133
134 // Handle "dev:" and "prod:" shorthands (copy to to cfg.Env)
135 if !cfg.Dev.IsZero() {
136 if cfg.EnvironmentOverrides == nil {
137 cfg.EnvironmentOverrides = make(map[string]yaml.Node)
138 }
139 cfg.EnvironmentOverrides["dev"] = cfg.Dev
140 }
141 if !cfg.Prod.IsZero() {
142 if cfg.EnvironmentOverrides == nil {
143 cfg.EnvironmentOverrides = make(map[string]yaml.Node)
144 }
145 cfg.EnvironmentOverrides["prod"] = cfg.Prod
146 }
147
148 // Set environment-specific override
149 if envOverride := cfg.EnvironmentOverrides[p.Environment]; !envOverride.IsZero() {
150 res.YAMLOverride = &envOverride
151
152 // Apply the override immediately in case it changes any of the commonYAML fields
153 err := res.YAMLOverride.Decode(cfg)
154 if err != nil {
155 return nil, pathError{path: ymlPath, err: newYAMLError(err)}
156 }
157 }
158

Callers 1

parseStemPathsMethod · 0.95

Calls 11

defaultOLAPConnectorMethod · 0.95
ExtractAnnotationsFunction · 0.92
newYAMLErrorFunction · 0.85
parseYAMLRefsFunction · 0.85
ParseResourceKindFunction · 0.85
AnalyzeTemplateFunction · 0.85
expandAnnotationsFunction · 0.85
pathStemFunction · 0.85
ErrorfMethod · 0.65
DecodeMethod · 0.45
IsZeroMethod · 0.45

Tested by

no test coverage detected