MCPcopy Index your code
hub / github.com/bytebase/bytebase / buildViewStmt

Function buildViewStmt

backend/plugin/parser/pg/query_span_loader_builders.go:72–88  ·  view source on GitHub ↗

buildViewStmt translates ViewMetadata into a ViewStmt. The view body is parsed via ParsePg; the result must be a *ast.SelectStmt (not a RawStmt wrapper) because omni's DefineView type-asserts directly. If the body is empty or unparseable, returns an error; the loader will pseudo the view using depe

(schema string, view *storepb.ViewMetadata)

Source from the content-addressed store, hash-verified

70// If the body is empty or unparseable, returns an error; the loader will
71// pseudo the view using dependency_columns metadata.
72func buildViewStmt(schema string, view *storepb.ViewMetadata) (*ast.ViewStmt, error) {
73 if view.Definition == "" {
74 return nil, errors.New("empty view definition")
75 }
76 sel, err := parseSelectBody(view.Definition)
77 if err != nil {
78 return nil, errors.Wrapf(err, "view %q body", view.Name)
79 }
80 return &ast.ViewStmt{
81 View: &ast.RangeVar{
82 Schemaname: schema,
83 Relname: view.Name,
84 Relpersistence: 'p',
85 },
86 Query: sel,
87 }, nil
88}
89
90// buildCreateTableAsStmt translates MaterializedViewMetadata into a
91// CreateTableAsStmt with Objtype OBJECT_MATVIEW. Same SelectStmt contract

Callers 3

installRealMethod · 0.85
TestLoaderBuildViewStmtFunction · 0.85

Calls 1

parseSelectBodyFunction · 0.85

Tested by 2

TestLoaderBuildViewStmtFunction · 0.68