@@ -101,7 +101,7 @@ class SessionCatalog(
101101
102102  /**  List of temporary views, mapping from table name to their logical plan. */  
103103  @ GuardedBy (" this" 
104-   protected  val  tempViews  =  new  mutable.HashMap [String , LogicalPlan ]
104+   protected  val  tempViews  =  new  mutable.HashMap [String , TemporaryViewRelation ]
105105
106106  //  Note: we track current database here because certain operations do not explicitly
107107  //  specify the database (e.g. DROP TABLE my_table). In these cases we must first
@@ -573,21 +573,21 @@ class SessionCatalog(
573573   */  
574574  def  createTempView (
575575      name : String ,
576-       tableDefinition :  LogicalPlan ,
576+       viewDefinition :  TemporaryViewRelation ,
577577      overrideIfExists : Boolean ):  Unit  =  synchronized  {
578578    val  table  =  formatTableName(name)
579579    if  (tempViews.contains(table) &&  ! overrideIfExists) {
580580      throw  new  TempTableAlreadyExistsException (name)
581581    }
582-     tempViews.put(table, tableDefinition )
582+     tempViews.put(table, viewDefinition )
583583  }
584584
585585  /**  
586586   * Create a global temporary view. 
587587   */  
588588  def  createGlobalTempView (
589589      name : String ,
590-       viewDefinition : LogicalPlan ,
590+       viewDefinition : TemporaryViewRelation ,
591591      overrideIfExists : Boolean ):  Unit  =  {
592592    globalTempViewManager.create(formatTableName(name), viewDefinition, overrideIfExists)
593593  }
@@ -598,7 +598,7 @@ class SessionCatalog(
598598   */  
599599  def  alterTempViewDefinition (
600600      name : TableIdentifier ,
601-       viewDefinition : LogicalPlan ):  Boolean  =  synchronized  {
601+       viewDefinition : TemporaryViewRelation ):  Boolean  =  synchronized  {
602602    val  viewName  =  formatTableName(name.table)
603603    if  (name.database.isEmpty) {
604604      if  (tempViews.contains(viewName)) {
@@ -617,14 +617,14 @@ class SessionCatalog(
617617  /**  
618618   * Return a local temporary view exactly as it was stored. 
619619   */  
620-   def  getRawTempView (name : String ):  Option [LogicalPlan ] =  synchronized  {
620+   def  getRawTempView (name : String ):  Option [TemporaryViewRelation ] =  synchronized  {
621621    tempViews.get(formatTableName(name))
622622  }
623623
624624  /**  
625625   * Generate a [[View ]] operator from the temporary view stored. 
626626   */  
627-   def  getTempView (name : String ):  Option [LogicalPlan ] =  synchronized  {
627+   def  getTempView (name : String ):  Option [View ] =  synchronized  {
628628    getRawTempView(name).map(getTempViewPlan)
629629  }
630630
@@ -635,14 +635,14 @@ class SessionCatalog(
635635  /**  
636636   * Return a global temporary view exactly as it was stored. 
637637   */  
638-   def  getRawGlobalTempView (name : String ):  Option [LogicalPlan ] =  {
638+   def  getRawGlobalTempView (name : String ):  Option [TemporaryViewRelation ] =  {
639639    globalTempViewManager.get(formatTableName(name))
640640  }
641641
642642  /**  
643643   * Generate a [[View ]] operator from the global temporary view stored. 
644644   */  
645-   def  getGlobalTempView (name : String ):  Option [LogicalPlan ] =  {
645+   def  getGlobalTempView (name : String ):  Option [View ] =  {
646646    getRawGlobalTempView(name).map(getTempViewPlan)
647647  }
648648
@@ -680,25 +680,10 @@ class SessionCatalog(
680680  def  getTempViewOrPermanentTableMetadata (name : TableIdentifier ):  CatalogTable  =  synchronized  {
681681    val  table  =  formatTableName(name.table)
682682    if  (name.database.isEmpty) {
683-       tempViews.get(table).map {
684-         case  TemporaryViewRelation (metadata, _) =>  metadata
685-         case  plan => 
686-           CatalogTable (
687-             identifier =  TableIdentifier (table),
688-             tableType =  CatalogTableType .VIEW ,
689-             storage =  CatalogStorageFormat .empty,
690-             schema =  plan.output.toStructType)
691-       }.getOrElse(getTableMetadata(name))
683+       tempViews.get(table).map(_.tableMeta).getOrElse(getTableMetadata(name))
692684    } else  if  (formatDatabaseName(name.database.get) ==  globalTempViewManager.database) {
693-       globalTempViewManager.get(table).map {
694-         case  TemporaryViewRelation (metadata, _) =>  metadata
695-         case  plan => 
696-           CatalogTable (
697-             identifier =  TableIdentifier (table, Some (globalTempViewManager.database)),
698-             tableType =  CatalogTableType .VIEW ,
699-             storage =  CatalogStorageFormat .empty,
700-             schema =  plan.output.toStructType)
701-       }.getOrElse(throw  new  NoSuchTableException (globalTempViewManager.database, table))
685+       globalTempViewManager.get(table).map(_.tableMeta)
686+         .getOrElse(throw  new  NoSuchTableException (globalTempViewManager.database, table))
702687    } else  {
703688      getTableMetadata(name)
704689    }
@@ -834,21 +819,9 @@ class SessionCatalog(
834819    }
835820  }
836821
837-   private  def  getTempViewPlan (plan : LogicalPlan ):  LogicalPlan  =  {
838-     plan match  {
839-       case  TemporaryViewRelation (tableMeta, None ) => 
840-         fromCatalogTable(tableMeta, isTempView =  true )
841-       case  TemporaryViewRelation (tableMeta, Some (plan)) => 
842-         View (desc =  tableMeta, isTempView =  true , child =  plan)
843-       case  other =>  other
844-     }
845-   }
846- 
847-   def  getTempViewSchema (plan : LogicalPlan ):  StructType  =  {
848-     plan match  {
849-       case  viewInfo : TemporaryViewRelation  =>  viewInfo.tableMeta.schema
850-       case  v =>  v.schema
851-     }
822+   private  def  getTempViewPlan (viewInfo : TemporaryViewRelation ):  View  =  viewInfo.plan match  {
823+     case  Some (p) =>  View (desc =  viewInfo.tableMeta, isTempView =  true , child =  p)
824+     case  None  =>  fromCatalogTable(viewInfo.tableMeta, isTempView =  true )
852825  }
853826
854827  private  def  fromCatalogTable (metadata : CatalogTable , isTempView : Boolean ):  View  =  {
@@ -909,7 +882,7 @@ class SessionCatalog(
909882    isTempView(nameParts.asTableIdentifier)
910883  }
911884
912-   def  lookupTempView (name : TableIdentifier ):  Option [LogicalPlan ] =  {
885+   def  lookupTempView (name : TableIdentifier ):  Option [View ] =  {
913886    val  tableName  =  formatTableName(name.table)
914887    if  (name.database.isEmpty) {
915888      tempViews.get(tableName).map(getTempViewPlan)
0 commit comments