org.apache.hcatalog.api
Class HCatClientHMSImpl

Object
  extended by HCatClient
      extended by HCatClientHMSImpl

public class HCatClientHMSImpl
extends HCatClient

The HCatClientHMSImpl is the Hive Metastore client based implementation of HCatClient.


Nested Class Summary
 
Nested classes/interfaces inherited from class HCatClient
HCatClient.DropDBMode
 
Field Summary
 
Fields inherited from class HCatClient
HCAT_CLIENT_IMPL_CLASS
 
Constructor Summary
HCatClientHMSImpl()
           
 
Method Summary
 void addPartition(HCatAddPartitionDesc partInfo)
          Adds the partition.
 int addPartitions(List<HCatAddPartitionDesc> partInfoList)
          Adds a list of partitions.
 void cancelDelegationToken(String tokenStrForm)
          Cancel delegation token.
 void close()
          Close the hcatalog client.
 void createDatabase(HCatCreateDBDesc dbInfo)
          Creates the database.
 void createTable(HCatCreateTableDesc createTableDesc)
          Creates the table.
 void createTableLike(String dbName, String existingTblName, String newTableName, boolean ifNotExists, boolean isExternal, String location)
          Creates the table like an existing table.
 void dropDatabase(String dbName, boolean ifExists, HCatClient.DropDBMode mode)
          Drops a database.
 void dropPartitions(String dbName, String tableName, Map<String,String> partitionSpec, boolean ifExists)
          Drops partition(s) that match the specified (and possibly partial) partition specification.
 void dropTable(String dbName, String tableName, boolean ifExists)
          Drop table.
 HCatDatabase getDatabase(String dbName)
          Gets the database.
 String getDelegationToken(String owner, String renewerKerberosPrincipalName)
          Gets the delegation token.
 String getMessageBusTopicName(String dbName, String tableName)
          Retrieve Message-bus topic for a table.
 HCatPartition getPartition(String dbName, String tableName, Map<String,String> partitionSpec)
          Gets the partition.
 List<HCatPartition> getPartitions(String dbName, String tblName)
          Gets all the partitions.
 List<HCatPartition> getPartitions(String dbName, String tblName, Map<String,String> partitionSpec)
          Gets all the partitions that match the specified (and possibly partial) partition specification.
 HCatTable getTable(String dbName, String tableName)
          Gets the table.
 boolean isPartitionMarkedForEvent(String dbName, String tblName, Map<String,String> partKVs, PartitionEventType eventType)
          Checks if a partition is marked for event.
 List<String> listDatabaseNamesByPattern(String pattern)
          Get all existing databases that match the given pattern.
 List<HCatPartition> listPartitionsByFilter(String dbName, String tblName, String filter)
          List partitions by filter.
 List<String> listTableNamesByPattern(String dbName, String tablePattern)
          Returns all existing tables from the specified database which match the given pattern.
 void markPartitionForEvent(String dbName, String tblName, Map<String,String> partKVs, PartitionEventType eventType)
          Mark partition for event.
 void renameTable(String dbName, String oldName, String newName)
          Renames a table.
 long renewDelegationToken(String tokenStrForm)
          Renew delegation token.
 void updateTableSchema(String dbName, String tableName, List<HCatFieldSchema> columnSchema)
          Updates the Table's column schema to the specified definition.
 
Methods inherited from class HCatClient
create
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HCatClientHMSImpl

public HCatClientHMSImpl()
Method Detail

listDatabaseNamesByPattern

public List<String> listDatabaseNamesByPattern(String pattern)
                                        throws HCatException
Description copied from class: HCatClient
Get all existing databases that match the given pattern. The matching occurs as per Java regular expressions

Specified by:
listDatabaseNamesByPattern in class HCatClient
Parameters:
pattern - java re pattern
Returns:
list of database names
Throws:
HCatException

getDatabase

public HCatDatabase getDatabase(String dbName)
                         throws HCatException
Description copied from class: HCatClient
Gets the database.

Specified by:
getDatabase in class HCatClient
Parameters:
dbName - The name of the database.
Returns:
An instance of HCatDatabaseInfo.
Throws:
HCatException

createDatabase

public void createDatabase(HCatCreateDBDesc dbInfo)
                    throws HCatException
Description copied from class: HCatClient
Creates the database.

Specified by:
createDatabase in class HCatClient
Parameters:
dbInfo - An instance of HCatCreateDBDesc.
Throws:
HCatException

dropDatabase

public void dropDatabase(String dbName,
                         boolean ifExists,
                         HCatClient.DropDBMode mode)
                  throws HCatException
Description copied from class: HCatClient
Drops a database.

Specified by:
dropDatabase in class HCatClient
Parameters:
dbName - The name of the database to delete.
ifExists - Hive returns an error if the database specified does not exist, unless ifExists is set to true.
mode - This is set to either "restrict" or "cascade". Restrict will remove the schema if all the tables are empty. Cascade removes everything including data and definitions.
Throws:
HCatException

listTableNamesByPattern

public List<String> listTableNamesByPattern(String dbName,
                                            String tablePattern)
                                     throws HCatException
Description copied from class: HCatClient
Returns all existing tables from the specified database which match the given pattern. The matching occurs as per Java regular expressions.

Specified by:
listTableNamesByPattern in class HCatClient
Parameters:
dbName - The name of the DB (to be searched)
tablePattern - The regex for the table-name
Returns:
list of table names
Throws:
HCatException

getTable

public HCatTable getTable(String dbName,
                          String tableName)
                   throws HCatException
Description copied from class: HCatClient
Gets the table.

Specified by:
getTable in class HCatClient
Parameters:
dbName - The name of the database.
tableName - The name of the table.
Returns:
An instance of HCatTableInfo.
Throws:
HCatException

createTable

public void createTable(HCatCreateTableDesc createTableDesc)
                 throws HCatException
Description copied from class: HCatClient
Creates the table.

Specified by:
createTable in class HCatClient
Parameters:
createTableDesc - An instance of HCatCreateTableDesc class.
Throws:
HCatException

updateTableSchema

public void updateTableSchema(String dbName,
                              String tableName,
                              List<HCatFieldSchema> columnSchema)
                       throws HCatException
Description copied from class: HCatClient
Updates the Table's column schema to the specified definition.

Specified by:
updateTableSchema in class HCatClient
Parameters:
dbName - The name of the database.
tableName - The name of the table.
columnSchema - The (new) definition of the column schema (i.e. list of fields).
Throws:
HCatException

createTableLike

public void createTableLike(String dbName,
                            String existingTblName,
                            String newTableName,
                            boolean ifNotExists,
                            boolean isExternal,
                            String location)
                     throws HCatException
Description copied from class: HCatClient
Creates the table like an existing table.

Specified by:
createTableLike in class HCatClient
Parameters:
dbName - The name of the database.
existingTblName - The name of the existing table.
newTableName - The name of the new table.
ifNotExists - If true, then error related to already table existing is skipped.
isExternal - Set to "true", if table has be created at a different location other than default.
location - The location for the table.
Throws:
HCatException

dropTable

public void dropTable(String dbName,
                      String tableName,
                      boolean ifExists)
               throws HCatException
Description copied from class: HCatClient
Drop table.

Specified by:
dropTable in class HCatClient
Parameters:
dbName - The name of the database.
tableName - The name of the table.
ifExists - Hive returns an error if the database specified does not exist, unless ifExists is set to true.
Throws:
HCatException

renameTable

public void renameTable(String dbName,
                        String oldName,
                        String newName)
                 throws HCatException
Description copied from class: HCatClient
Renames a table.

Specified by:
renameTable in class HCatClient
Parameters:
dbName - The name of the database.
oldName - The name of the table to be renamed.
newName - The new name of the table.
Throws:
HCatException

getPartitions

public List<HCatPartition> getPartitions(String dbName,
                                         String tblName)
                                  throws HCatException
Description copied from class: HCatClient
Gets all the partitions.

Specified by:
getPartitions in class HCatClient
Parameters:
dbName - The name of the database.
tblName - The name of the table.
Returns:
A list of partitions.
Throws:
HCatException

getPartitions

public List<HCatPartition> getPartitions(String dbName,
                                         String tblName,
                                         Map<String,String> partitionSpec)
                                  throws HCatException
Description copied from class: HCatClient
Gets all the partitions that match the specified (and possibly partial) partition specification. A partial partition-specification is one where not all partition-keys have associated values. For example, for a table ('myDb.myTable') with 2 partition keys (dt string, region string), if for each dt ('20120101', '20120102', etc.) there can exist 3 regions ('us', 'uk', 'in'), then, 1. Complete partition spec: getPartitions('myDb', 'myTable', {dt='20120101', region='us'}) would return 1 partition. 2. Partial partition spec: getPartitions('myDb', 'myTable', {dt='20120101'}) would return all 3 partitions, with dt='20120101' (i.e. region = 'us', 'uk' and 'in').

Specified by:
getPartitions in class HCatClient
Parameters:
dbName - The name of the database.
tblName - The name of the table.
partitionSpec - The partition specification. (Need not include all partition keys.)
Returns:
A list of partitions.
Throws:
HCatException

getPartition

public HCatPartition getPartition(String dbName,
                                  String tableName,
                                  Map<String,String> partitionSpec)
                           throws HCatException
Description copied from class: HCatClient
Gets the partition.

Specified by:
getPartition in class HCatClient
Parameters:
dbName - The database name.
tableName - The table name.
partitionSpec - The partition specification, {[col_name,value],[col_name2,value2]}. All partition-key-values must be specified.
Returns:
An instance of HCatPartitionInfo.
Throws:
HCatException

addPartition

public void addPartition(HCatAddPartitionDesc partInfo)
                  throws HCatException
Description copied from class: HCatClient
Adds the partition.

Specified by:
addPartition in class HCatClient
Parameters:
partInfo - An instance of HCatAddPartitionDesc.
Throws:
HCatException

dropPartitions

public void dropPartitions(String dbName,
                           String tableName,
                           Map<String,String> partitionSpec,
                           boolean ifExists)
                    throws HCatException
Description copied from class: HCatClient
Drops partition(s) that match the specified (and possibly partial) partition specification. A partial partition-specification is one where not all partition-keys have associated values. For example, for a table ('myDb.myTable') with 2 partition keys (dt string, region string), if for each dt ('20120101', '20120102', etc.) there can exist 3 regions ('us', 'uk', 'in'), then, 1. Complete partition spec: dropPartitions('myDb', 'myTable', {dt='20120101', region='us'}) would drop 1 partition. 2. Partial partition spec: dropPartitions('myDb', 'myTable', {dt='20120101'}) would drop all 3 partitions, with dt='20120101' (i.e. region = 'us', 'uk' and 'in').

Specified by:
dropPartitions in class HCatClient
Parameters:
dbName - The database name.
tableName - The table name.
partitionSpec - The partition specification, {[col_name,value],[col_name2,value2]}.
ifExists - Hive returns an error if the partition specified does not exist, unless ifExists is set to true.
Throws:
HCatException

listPartitionsByFilter

public List<HCatPartition> listPartitionsByFilter(String dbName,
                                                  String tblName,
                                                  String filter)
                                           throws HCatException
Description copied from class: HCatClient
List partitions by filter.

Specified by:
listPartitionsByFilter in class HCatClient
Parameters:
dbName - The database name.
tblName - The table name.
filter - The filter string, for example "part1 = \"p1_abc\" and part2 <= "\p2_test\"". Filtering can be done only on string partition keys.
Returns:
list of partitions
Throws:
HCatException

markPartitionForEvent

public void markPartitionForEvent(String dbName,
                                  String tblName,
                                  Map<String,String> partKVs,
                                  PartitionEventType eventType)
                           throws HCatException
Description copied from class: HCatClient
Mark partition for event.

Specified by:
markPartitionForEvent in class HCatClient
Parameters:
dbName - The database name.
tblName - The table name.
partKVs - the key-values associated with the partition.
eventType - the event type
Throws:
HCatException

isPartitionMarkedForEvent

public boolean isPartitionMarkedForEvent(String dbName,
                                         String tblName,
                                         Map<String,String> partKVs,
                                         PartitionEventType eventType)
                                  throws HCatException
Description copied from class: HCatClient
Checks if a partition is marked for event.

Specified by:
isPartitionMarkedForEvent in class HCatClient
Parameters:
dbName - the db name
tblName - the table name
partKVs - the key-values associated with the partition.
eventType - the event type
Returns:
true, if is partition marked for event
Throws:
HCatException

getDelegationToken

public String getDelegationToken(String owner,
                                 String renewerKerberosPrincipalName)
                          throws HCatException
Description copied from class: HCatClient
Gets the delegation token.

Specified by:
getDelegationToken in class HCatClient
Parameters:
owner - the owner
renewerKerberosPrincipalName - the renewer kerberos principal name
Returns:
the delegation token
Throws:
HCatException

renewDelegationToken

public long renewDelegationToken(String tokenStrForm)
                          throws HCatException
Description copied from class: HCatClient
Renew delegation token.

Specified by:
renewDelegationToken in class HCatClient
Parameters:
tokenStrForm - the token string
Returns:
the new expiration time
Throws:
HCatException

cancelDelegationToken

public void cancelDelegationToken(String tokenStrForm)
                           throws HCatException
Description copied from class: HCatClient
Cancel delegation token.

Specified by:
cancelDelegationToken in class HCatClient
Parameters:
tokenStrForm - the token string
Throws:
HCatException

close

public void close()
           throws HCatException
Description copied from class: HCatClient
Close the hcatalog client.

Specified by:
close in class HCatClient
Throws:
HCatException

addPartitions

public int addPartitions(List<HCatAddPartitionDesc> partInfoList)
                  throws HCatException
Description copied from class: HCatClient
Adds a list of partitions.

Specified by:
addPartitions in class HCatClient
Parameters:
partInfoList - A list of HCatAddPartitionDesc.
Returns:
The number of partitions added.
Throws:
HCatException

getMessageBusTopicName

public String getMessageBusTopicName(String dbName,
                                     String tableName)
                              throws HCatException
Description copied from class: HCatClient
Retrieve Message-bus topic for a table.

Specified by:
getMessageBusTopicName in class HCatClient
Parameters:
dbName - The name of the DB.
tableName - The name of the table.
Returns:
Topic-name for the message-bus on which messages will be sent for the specified table. By default, this is set to .. Returns null when not set.
Throws:
HCatException