Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

– This document is a work in progress.

Overview

There are presently three ways to issue HCatalog DDL commands:

...

Code Block
public abstract class HCatClient {

    /**
     * Creates an instance of HCatClient.
     *
     * @param conf An instance of configuration.
     * @return An instance of HCatClient.
     * @throws IOException
     */
    public static HCatClient create(Configuration conf) throws IOException{
      HCatClient client  return null= HCatUtil.getHCatClient(conf);
    }

    /**
  if(client != null){
   * Get all existing databases that match the given
  client.initialize(conf);
        *}
 pattern. The matching occurs as per Java regularreturn expressionsclient;
    }

  *
  abstract void initialize(Configuration *conf) @paramthrows databasePatternHCatException;

    /**
 *    * Get all existing databases that javamatch rethe patterngiven
     * @return list of database namespattern. The matching occurs as per Java regular expressions
     *
 @throws HCatException
   * @param */databasePattern
     *  public abstract List<String> listDatabasesByPattern(String pattern) throws HCatException;

  java re /**pattern
     * @return Getslist theof database. names
     * @throws HCatException
     */
    public abstract List<String> listDatabaseNamesByPattern(String pattern) throws HCatException;

    /**
     * Gets the database.
     *
     * @param dbName The name of the database.
     * @return An instance of HCatDatabaseInfo.
     * @throws HCatException
     */
    public abstract HCatDatabase getDatabase(String dbName) throws HCatException;

    /**
     * Creates the database.
     *
     * @param dbInfo An instance of HCatCreateDBDesc.
     * @throws HCatException
     */
    public abstract void createDatabase(HCatCreateDBDesc dbInfo)
            throws HCatException;

    /**
     * Drops a database.
     *
     * @param dbName The name of the database to delete.
     * @param ifExists Hive returns an error if the database specified does not exist,
     *                 unless ifExists is set to true.
     * @param 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
     */
    public abstract void dropDatabase(String dbName, boolean ifExists, String mode) throws HCatException;

    /**
     * Returns all existing tables from the specified database which match the given
     * pattern. The matching occurs as per Java regular expressions.
     * @param dbName
     * @param tablePattern
     * @return list of table names
     * @throws HCatException
     */
    public abstract List<String> listTablesByPatternlistTableNamesByPattern(String dbName, String tablePattern)
            throws HCatException;

    /**
     * Gets the table.
     *
     * @param dbName The name of the database.
     * @param tableName The name of the table.
     * @return An instance of HCatTableInfo.
     * @throws HCatException
     */
    public abstract HCatTable getTable(String dbName, String tableName)
            throws HCatException;

    /**
     * Creates the table.
     *
     * @param createTableDesc An instance of HCatCreateTableDesc class.
     * @throws HCatException the h cat exception
     */
    public abstract void createTable(HCatCreateTableDesc createTableDesc)
            throws HCatException;

    /**
     * Creates the table like an existing table.
     *
     * @param dbName The name of the database.
     * @param existingTblName The name of the existing table.
     * @param newTableName The name of the new table.
     * @param ifExists the if existsifNotExists If true, then error related to already table existing is skipped.
     * @param isExternal Set to "true", if table has be created at a different
     *                   location other than default.
     * @param location The location for the table.
     * @throws HCatException
     */
    public abstract void createTableLike(String dbName, String existingTblName,
            String newTableName, boolean ifExistsifNotExists, boolean isExternal,
            String location) throws HCatException;

    /**
     * Drop table.
     *
     * @param dbName The name of the database.
     * @param tableName The name of the table.
     * @param ifExists Hive returns an error if the database specified does not exist,
     *                 unless ifExists is set to true.
     * @throws HCatException
     */
    public abstract void dropTable(String dbName, String tableName,
            boolean ifExists) throws HCatException;

    /**
     * Renames a table.
     *
     * @param dbName The name of the database.
     * @param oldName The name of the table to be renamed.
     * @param newName The new name of the table.
     * @throws HCatException
     */
    public abstract void renameTable(String dbName, String oldName, String newName) throws HCatException;

    /**
     * Gets all the partitions.
     *
     * @param dbName The name of the database.
     * @param tblName The name of the table.
     * @return A list of partition names.
     * @throws HCatException the h cat exception
     */
    public abstract List<HCatPartition> getPartitions(String dbName, String tblName)
            throws HCatException;

    /**
     * Gets the partition.
     *
     * @param dbName The database name.
     * @param tableName The table name.
     * @param partitionName The partition name, Comma separated list of col_name='value'.
     * @return An instance of HCatPartitionInfo.
     * @throws HCatException
     */
    public abstract HCatPartition getPartition(String dbName, String tableName,
            String partitionName) throws HCatException;

    /**
     * Adds the partition.
     *
     * @param partInfo An instance of HCatAddPartitionDesc.
     * @throws HCatException the h cat exception
     */
    public abstract void addPartition(HCatAddPartitionDesc partInfo) throws HCatException;

    /**
     * Drops partition.
     *
     * @param dbName The database name.
     * @param tableName The table name.
     * @param partitionName The partition name, Comma separated list of col_name='value'.
     * @param ifExists Hive returns an error if the partition specified does not exist, unless ifExists is set to true.
     * @throws HCatException
     */
    public abstract void dropPartition(String dbName, String tableName,
            String partitionName, boolean ifExists) throws HCatException;

    /**
     * List partitions by filter.
     *
     * @param dbName The database name.
     * @param tblName The table name.
     * @param filter The filter string,
     *    for example "part1 = \"p1_abc\" and part2 <= "\p2_test\"". Filtering can
     *    be done only on string partition keys.
     * @return list of partitions
     * @throws HCatException the h cat exception
     */
    public abstract List<HCatPartition> listPartitionsByFilter(String dbName, String tblName,
            String filter) throws HCatException;

    /**
     * Mark partition for event.
     *
     * @param dbName The database name.
     * @param tblName The table name.
     * @param partKVs the part k vs
     * @param eventType the event type
     * @throws HCatException the h cat exception
     */
    public abstract void markPartitionForEvent(String dbName, String tblName,
            Map<String, String> partKVs, PartitionEventType eventType)
            throws HCatException;

    /**
     * Checks if is partition marked for event.
     *
     * @param dbName the db name
     * @param tblName the tbl name
     * @param partKVs the part k vs
     * @param partKVs the part k vs eventType the event type
     * @return true, if is partition marked for event
     * @throws HCatException the h cat exception
     */
    public abstract boolean isPartitionMarkedForEvent(String dbName, String tblName,
            Map<String, String> partKVs, PartitionEventType eventType)
            throws HCatException;

    /**
     * @param eventTypeGets the eventdelegation typetoken.
     *
  @return true, if is* partition@param markedowner forthe eventowner
     * @throws@param HCatExceptionrenewerKerberosPrincipalName the renewer hkerberos catprincipal exceptionname
     */
 @return the delegation public abstracttoken
 boolean isPartitionMarkedForEvent(String dbName,  String* tblName,
@throws HCatException the h cat exception
     */
  Map<String, String> partKVs,public PartitionEventTypeabstract eventType)
     String getDelegationToken(String owner, String renewerKerberosPrincipalName) throws
       throws HCatException;

    /**
     * Gets theRenew delegation token.
     *
     * @param renewerKerberosPrincipalNametokenStrForm the renewertoken kerberosstr principal nameform
     * @return the delegation tokenlong
     * @throws HCatException the h cat exception
     */
    public abstract Stringlong getDelegationTokenrenewDelegationToken(String renewerKerberosPrincipalNametokenStrForm) throws
        HCatException;

    /**
     * RenewCancel delegation token.
     *
     * @param tokenStrForm the token str form
     * @return the long
     * @throws HCatException the h cat exception
     */
    public abstract longvoid renewDelegationTokencancelDelegationToken(String tokenStrForm) throws HCatException;

    /**
     * Close Cancelthe delegationhcatalog token.
     *client.
     * @param tokenStrForm the token str form
     * @throws HCatException the h cat exception
     */
    public abstract void cancelDelegationTokenclose(String tokenStrForm) throws HCatException;

}
HCatCreateTableDesc

This class is a sub class of HCatCommandDesc and will be used by the users to create descriptor and validate it for the "create table" command.
Image Removed Image Added

HCatCreateDBDesc

This class is a sub class of HCatCommandDesc and will be used by the users to create descriptors and validate it for the "create database" command.

Image Removed!createdb.png|

HCatAddPartitionDesc

This class is a sub class of HCatCommandDesc and will be used by the users to create descriptors and validate it for the "add partition" command.

Image Removed Image Added

HCatTable

This class encapsulates the table information returned the HCatClient implementation class and provides a uniform view to the user.

...

Code Block
 Configuration config = new Configuration();
 config.add("hive-site.xml");
 HCatClient client = HCatClient.create(config);
 ArrayList<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>();
 cols.add(new HCatFieldSchema("col1id", Type.INT, "comment1id columns"));
 cols.add(new HCatFieldSchema("col2value", Type.STRING, "comment2id columns"));
HCatCreateTableDesc desctableDesc = new HCatCreateTableDesc.Buildercreate(db, "defaulttesttable","demo_table" cols).fileFormat("rcfile").cols(cols).build();

 boolean success = client.createTable(desctableDesc);

Discussion Topics