@@ -35,10 +35,11 @@ abstract class SessionCatalog(catalog: ExternalCatalog) {
3535
3636  private [this ] val  tempFunctions  =  new  ConcurrentHashMap [String , CatalogFunction ]
3737
38-   //  --------------------------------------------------------------------------
38+   //  ---------------------------------------------------------------------------- 
3939  //  Databases
40+   //  ----------------------------------------------------------------------------
4041  //  All methods in this category interact directly with the underlying catalog.
41-   //  --------------------------------------------------------------------------
42+   //  ---------------------------------------------------------------------------- 
4243
4344  def  createDatabase (dbDefinition : CatalogDatabase , ignoreIfExists : Boolean ):  Unit 
4445
@@ -54,76 +55,90 @@ abstract class SessionCatalog(catalog: ExternalCatalog) {
5455
5556  def  listDatabases (pattern : String ):  Seq [String ]
5657
57-   //  --------------------------------------------------------------------------
58+   //  ---------------------------------------------------------------------------- 
5859  //  Tables
59-   //  --------------------------------------------------------------------------
60- 
61-   //  --------------------------------------------------------------------------
62-   //  Tables: Methods for metastore tables.
63-   //  Methods in this category are only used for metastore tables, which store
64-   //  metadata in the underlying catalog.
65-   //  --------------------------------------------------------------------------
60+   //  ----------------------------------------------------------------------------
61+   //  There are two kinds of tables, temporary tables and metastore tables.
62+   //  Temporary tables are isolated across sessions and do not belong to any
63+   //  particular database. Metastore tables can be used across multiple
64+   //  sessions as their metadata is persisted in the underlying catalog.
65+   //  ----------------------------------------------------------------------------
6666
67-   def  createTable (db : String , tableDefinition : CatalogTable , ignoreIfExists : Boolean ):  Unit 
67+   /**  
68+    * Create a metastore table in the database specified in `tableDefinition`. 
69+    * If no such table is specified, create it in the current database. 
70+    */  
71+   def  createTable (
72+       currentDb : String ,
73+       tableDefinition : CatalogTable ,
74+       ignoreIfExists : Boolean ):  Unit 
6875
6976  /**  
70-    * Alters a table whose name matches the one specified in `tableDefinition`, 
71-    * assuming the table exists. 
77+    * Alter the metadata of an existing metastore table identified by `tableDefinition`. 
7278   * 
7379   * Note: If the underlying implementation does not support altering a certain field, 
7480   * this becomes a no-op. 
7581   */  
76-   def  alterTable (db :  String ,  tableDefinition : CatalogTable ):  Unit 
82+   def  alterTable (tableDefinition : CatalogTable ):  Unit 
7783
7884  /**  
79-    * Retrieves  the metadata of a table called ` table` in the database `db` . 
85+    * Retrieve  the metadata of an existing metastore  table. 
8086   */  
81-   def  getTable (db : String , table : String ):  CatalogTable 
82- 
83-   //  --------------------------------------------------------------------------
84-   //  Tables: Methods for metastore tables or temp tables.
85-   //  --------------------------------------------------------------------------
87+   def  getTableMetadata (name : TableIdentifier ):  CatalogTable 
8688
8789  /**  
88-    * Creates  a temporary table. If there is already a temporary table having the same name,  
89-    * the table definition of that table will be updated to the new definition . 
90+    * Create  a temporary table. 
91+    * If a temporary table with the same name already exists, this throws an exception . 
9092   */  
91-   //  TODO: Should we automatically overwrite the existing temp table?
92-   //  Postgres and Hive will complain if a temp table is already defined.
93-   def  createTempTable (tableIdent : TableIdentifier , tableDefinition : LogicalPlan ):  Unit 
93+   def  createTempTable (name : String , tableDefinition : LogicalPlan ):  Unit 
9494
95+   /**  
96+    * Rename a table. 
97+    * 
98+    * If a database is specified in `oldName`, this will rename the table in that database. 
99+    * If no database is specified, this will first attempt to rename a temporary table with 
100+    * the same name, then, if that does not exist, rename the table in the current database. 
101+    * 
102+    * This assumes the database specified in `oldName` matches the one specified in `newName`. 
103+    */  
95104  def  renameTable (
96-       specifiedDB : Option [String ],
97-       currentDB : String ,
98-       oldName : String ,
99-       newName : String ):  Unit 
105+       currentDb : String ,
106+       oldName : TableIdentifier ,
107+       newName : TableIdentifier ):  Unit 
100108
101109  /**  
102-    * Drops a table. If a database name is not provided, this method will drop the table with 
103-    * the given name from the temporary table name space as well as the table 
104-    * in the current database. If a database name is provided, this method only drops the table 
105-    * with the given name from the given database. 
110+    * Drop a table. 
111+    * 
112+    * If a database is specified in `name`, this will drop the table from that database. 
113+    * If no database is specified, this will first attempt to drop a temporary table with 
114+    * the same name, then, if that does not exist, drop the table from the current database. 
106115   */  
107-   //  TODO: When a temp table and a table in the current db have the same name, should we
108-   //  only drop the temp table when a database is not provided (Postgresql's semantic)?
109116  def  dropTable (
110-       tableIdent :  TableIdentifier ,
111-       currentDB :  String ,
117+       currentDb :  String ,
118+       name :  TableIdentifier ,
112119      ignoreIfNotExists : Boolean ):  Unit 
113120
114121  /**  
115-    * Returns a [[LogicalPlan ]] representing the requested table. This method is used 
116-    * when we need to create a query plan for a given table. 
122+    * Return a [[LogicalPlan ]] that represents the given table. 
117123   * 
118-    * This method  is different from `getTable `, which only returns  the metadata of the table  
119-    * in the form of [[ CatalogTable ]]. The [[ LogicalPlan ]] returned by this method contains  
120-    * the metadata of  the table in  the form of [[ CatalogTable ]] . 
124+    * If a database  is specified in `name `, this will return  the table from that database.  
125+    * If no database is specified, this will first attempt to return a temporary table with  
126+    * the same name, then, if that does not exist, return  the table from  the current database . 
121127   */  
122-   def  lookupRelation (tableIdent : TableIdentifier , alias : Option [String ] =  None ):  LogicalPlan 
128+   def  lookupRelation (
129+       currentDb : String ,
130+       name : TableIdentifier ,
131+       alias : Option [String ] =  None ):  LogicalPlan 
123132
124-   def  listTables (specifiedDB : Option [String ], currentDB : String ):  Seq [String ]
133+   /**  
134+    * List all tables in the current database, including temporary tables. 
135+    */  
136+   def  listTables (currentDb : String ):  Seq [TableIdentifier ]
125137
126-   def  listTables (specifiedDB : Option [String ], currentDB : String , pattern : String ):  Seq [String ]
138+   /**  
139+    * List all matching tables in the current database, including temporary tables. 
140+    */  
141+   def  listTables (currentDb : String , pattern : String ):  Seq [TableIdentifier ]
127142
128143  //  --------------------------------------------------------------------------
129144  //  Partitions
0 commit comments