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)
| 70 | // If the body is empty or unparseable, returns an error; the loader will |
| 71 | // pseudo the view using dependency_columns metadata. |
| 72 | func 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 |