@@ -28,6 +28,7 @@ import (
2828
2929 "github.com/dolthub/go-mysql-server/sql"
3030 "github.com/dolthub/go-mysql-server/sql/mysql_db"
31+ "github.com/dolthub/go-mysql-server/sql/planbuilder"
3132 "github.com/dolthub/go-mysql-server/sql/transform"
3233 "github.com/dolthub/go-mysql-server/sql/types"
3334)
@@ -235,7 +236,7 @@ func columnsRowIter(ctx *sql.Context, catalog sql.Catalog, allColsWithDefaultVal
235236 }
236237 rows = append (rows , rs ... )
237238
238- rs , err = getRowsFromViews (ctx , db )
239+ rs , err = getRowsFromViews (ctx , catalog , db , privSet , globalPrivSetMap )
239240 if err != nil {
240241 return nil , err
241242 }
@@ -364,41 +365,28 @@ func getRowsFromTable(ctx *sql.Context, db DbWithNames, t sql.Table, privSetDb s
364365}
365366
366367// getRowsFromViews returns array or rows for columns for all views for given database.
367- func getRowsFromViews (ctx * sql.Context , db DbWithNames ) ([]sql.Row , error ) {
368+ func getRowsFromViews (ctx * sql.Context , catalog sql. Catalog , db DbWithNames , privSet sql. PrivilegeSet , privSetMap map [ string ] struct {} ) ([]sql.Row , error ) {
368369 var rows []sql.Row
369- // TODO: View Definition is lacking information to properly fill out these table
370- // TODO: Should somehow get reference to table(s) view is referencing
371- // TODO: Each column that view references should also show up as unique entries as well
372370 views , err := ViewsInDatabase (ctx , db .Database )
373371 if err != nil {
374372 return nil , err
375373 }
376374
377- for _ , view := range views {
378- rows = append (rows , sql.Row {
379- db .CatalogName , // table_catalog
380- db .SchemaName , // table_schema
381- view .Name , // table_name
382- "" , // column_name
383- uint32 (0 ), // ordinal_position
384- nil , // column_default
385- "" , // is_nullable
386- nil , // data_type
387- nil , // character_maximum_length
388- nil , // character_octet_length
389- nil , // numeric_precision
390- nil , // numeric_scale
391- nil , // datetime_precision
392- "" , // character_set_name
393- "" , // collation_name
394- "" , // column_type
395- "" , // column_key
396- "" , // extra
397- "select" , // privileges
398- "" , // column_comment
399- "" , // generation_expression
400- nil , // srs_id
401- })
375+ for i , view := range views {
376+ node , _ , err := planbuilder .Parse (ctx , catalog , view .TextDefinition )
377+ if err != nil {
378+ // TODO: should we error?
379+ continue
380+ }
381+ privSetDb := privSet .Database (db .Database .Name ())
382+ privSetTbl := privSetDb .Table (view .Name )
383+ curPrivSetMap := getCurrentPrivSetMapForColumn (privSetDb .ToSlice (), privSetMap )
384+ for _ , col := range node .Schema () {
385+ r := getRowFromColumn (ctx , i , col , db .CatalogName , db .SchemaName , view .Name , "" , privSetTbl , curPrivSetMap )
386+ if r != nil {
387+ rows = append (rows , r )
388+ }
389+ }
402390 }
403391
404392 return rows , nil
0 commit comments