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

Method parseStemPaths

runtime/parser/parser.go:693–774  ·  view source on GitHub ↗

parseStem parses a set of paths with the same stem (path without extension).

(ctx context.Context, paths []string)

Source from the content-addressed store, hash-verified

691
692// parseStem parses a set of paths with the same stem (path without extension).
693func (p *Parser) parseStemPaths(ctx context.Context, paths []string) error {
694 // Load YAML and SQL contents
695 var yaml, yamlPath, sql, sqlPath string
696 var found bool
697 for _, path := range paths {
698 // Load contents
699 data, err := p.Repo.Get(ctx, path)
700 if err != nil {
701 if os.IsNotExist(err) {
702 // This is a dirty parse where a file disappeared during parsing.
703 // But due to the clear-and-rebuild behavior, we can safely continue parsing.
704 continue
705 }
706 return err
707 }
708
709 // Check size
710 if len(data) > maxFileSize {
711 p.Errors = append(p.Errors, &runtimev1.ParseError{
712 Message: fmt.Sprintf("size %d bytes exceeds max size of %d bytes", len(data), maxFileSize),
713 FilePath: path,
714 })
715 continue
716 }
717
718 // Assign to correct variable
719 if strings.HasSuffix(path, ".sql") {
720 sql = data
721 sqlPath = path
722 found = true
723 continue
724 }
725 if strings.HasSuffix(path, ".yaml") || strings.HasSuffix(path, ".yml") {
726 if yaml != "" {
727 // Means there was both a .yaml and .yml file. We don't allow that!
728 p.Errors = append(p.Errors, &runtimev1.ParseError{
729 Message: "skipping file because another YAML file has already been parsed for this path stem",
730 FilePath: path,
731 })
732 continue
733 }
734 yaml = data
735 yamlPath = path
736 found = true
737 continue
738 }
739 // The unhandled case should never happen, just being defensive
740 }
741
742 // There's a few cases above where we don't find YAML or SQL contents. It's fine to just skip the file in those cases.
743 if !found {
744 return nil
745 }
746
747 // Parse the SQL/YAML file pair to a Node, then parse the Node to p.Resources.
748 node, err := p.parseStem(paths, yamlPath, yaml, sqlPath, sql)
749 if err == nil {
750 err = p.parseNode(ctx, node)

Callers 1

parsePathsMethod · 0.95

Calls 5

parseStemMethod · 0.95
parseNodeMethod · 0.95
addParseErrorMethod · 0.95
GetMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected