org.apache.hcatalog.common
Class HCatUtil

java.lang.Object
  extended by org.apache.hcatalog.common.HCatUtil

public class HCatUtil
extends java.lang.Object


Constructor Summary
HCatUtil()
           
 
Method Summary
static void cancelJobTrackerDelegationToken(java.lang.String tokenStrForm, java.lang.String tokenSignature)
           
static boolean checkJobContextIfRunningFromBackend(org.apache.hadoop.mapreduce.JobContext j)
           
static byte[] decodeBytes(java.lang.String str)
           
static java.lang.Object deserialize(java.lang.String str)
           
static java.lang.String encodeBytes(byte[] bytes)
           
static org.apache.hadoop.security.token.Token<org.apache.hadoop.mapreduce.security.token.delegation.DelegationTokenIdentifier> extractJobTrackerToken(java.lang.String tokenStrForm, java.lang.String tokenSignature)
           
static HCatSchema extractSchemaFromStorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor sd)
           
static org.apache.hadoop.security.token.Token<? extends org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier> extractThriftToken(java.lang.String tokenStrForm, java.lang.String tokenSignature)
           
static java.util.List<org.apache.hadoop.hive.metastore.api.FieldSchema> getFieldSchemaList(java.util.List<HCatFieldSchema> hcatFields)
           
static java.util.List<HCatFieldSchema> getHCatFieldSchemaList(org.apache.hadoop.hive.metastore.api.FieldSchema... fields)
           
static java.util.List<HCatFieldSchema> getHCatFieldSchemaList(java.util.List<org.apache.hadoop.hive.metastore.api.FieldSchema> fields)
           
static org.apache.hadoop.security.token.Token<org.apache.hadoop.mapreduce.security.token.delegation.DelegationTokenIdentifier> getJobTrackerDelegationToken(org.apache.hadoop.conf.Configuration conf, java.lang.String userName)
           
static org.apache.hadoop.hive.metastore.api.Table getTable(org.apache.hadoop.hive.metastore.HiveMetaStoreClient client, java.lang.String dbName, java.lang.String tableName)
           
static HCatSchema getTableSchemaWithPtnCols(org.apache.hadoop.hive.metastore.api.Table table)
           
static void logAllTokens(org.apache.commons.logging.Log logger, org.apache.hadoop.mapreduce.JobContext context)
           
static void logEntrySet(org.apache.commons.logging.Log logger, java.lang.String itemName, java.util.Set<? extends java.util.Map.Entry> entrySet)
           
static void logHiveConf(org.apache.commons.logging.Log logger, org.apache.hadoop.hive.conf.HiveConf hc)
          debug log the hive conf
static void logList(org.apache.commons.logging.Log logger, java.lang.String itemName, java.util.List<? extends java.lang.Object> list)
           
static void logMap(org.apache.commons.logging.Log logger, java.lang.String itemName, java.util.Map<? extends java.lang.Object,? extends java.lang.Object> map)
           
static void logStackTrace(org.apache.commons.logging.Log logger)
          Logging stack trace
static void logToken(org.apache.commons.logging.Log logger, java.lang.String itemName, org.apache.hadoop.security.token.Token<? extends org.apache.hadoop.security.token.TokenIdentifier> t)
           
static java.lang.String serialize(java.io.Serializable obj)
           
static boolean validateExecuteBitPresentIfReadOrWrite(org.apache.hadoop.fs.permission.FsAction perms)
          Ensure that read or write permissions are not granted without also granting execute permissions.
static boolean validateMorePermissive(org.apache.hadoop.fs.permission.FsAction first, org.apache.hadoop.fs.permission.FsAction second)
          Test if the first FsAction is more permissive than the second.
static java.util.List<org.apache.hadoop.hive.metastore.api.FieldSchema> validatePartitionSchema(org.apache.hadoop.hive.metastore.api.Table table, HCatSchema partitionSchema)
          Validate partition schema, checks if the column types match between the partition and the existing table schema.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HCatUtil

public HCatUtil()
Method Detail

checkJobContextIfRunningFromBackend

public static boolean checkJobContextIfRunningFromBackend(org.apache.hadoop.mapreduce.JobContext j)

serialize

public static java.lang.String serialize(java.io.Serializable obj)
                                  throws java.io.IOException
Throws:
java.io.IOException

deserialize

public static java.lang.Object deserialize(java.lang.String str)
                                    throws java.io.IOException
Throws:
java.io.IOException

encodeBytes

public static java.lang.String encodeBytes(byte[] bytes)

decodeBytes

public static byte[] decodeBytes(java.lang.String str)

getHCatFieldSchemaList

public static java.util.List<HCatFieldSchema> getHCatFieldSchemaList(org.apache.hadoop.hive.metastore.api.FieldSchema... fields)
                                                              throws HCatException
Throws:
HCatException

getHCatFieldSchemaList

public static java.util.List<HCatFieldSchema> getHCatFieldSchemaList(java.util.List<org.apache.hadoop.hive.metastore.api.FieldSchema> fields)
                                                              throws HCatException
Throws:
HCatException

extractSchemaFromStorageDescriptor

public static HCatSchema extractSchemaFromStorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor sd)
                                                     throws HCatException
Throws:
HCatException

getFieldSchemaList

public static java.util.List<org.apache.hadoop.hive.metastore.api.FieldSchema> getFieldSchemaList(java.util.List<HCatFieldSchema> hcatFields)

getTable

public static org.apache.hadoop.hive.metastore.api.Table getTable(org.apache.hadoop.hive.metastore.HiveMetaStoreClient client,
                                                                  java.lang.String dbName,
                                                                  java.lang.String tableName)
                                                           throws java.lang.Exception
Throws:
java.lang.Exception

getTableSchemaWithPtnCols

public static HCatSchema getTableSchemaWithPtnCols(org.apache.hadoop.hive.metastore.api.Table table)
                                            throws java.io.IOException
Throws:
java.io.IOException

validatePartitionSchema

public static java.util.List<org.apache.hadoop.hive.metastore.api.FieldSchema> validatePartitionSchema(org.apache.hadoop.hive.metastore.api.Table table,
                                                                                                       HCatSchema partitionSchema)
                                                                                                throws java.io.IOException
Validate partition schema, checks if the column types match between the partition and the existing table schema. Returns the list of columns present in the partition but not in the table.

Parameters:
table - the table
partitionSchema - the partition schema
Returns:
the list of newly added fields
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

validateMorePermissive

public static boolean validateMorePermissive(org.apache.hadoop.fs.permission.FsAction first,
                                             org.apache.hadoop.fs.permission.FsAction second)
Test if the first FsAction is more permissive than the second. This is useful in cases where we want to ensure that a file owner has more permissions than the group they belong to, for eg. More completely(but potentially more cryptically) owner-r >= group-r >= world-r : bitwise and-masked with 0444 => 444 >= 440 >= 400 >= 000 owner-w >= group-w >= world-w : bitwise and-masked with &0222 => 222 >= 220 >= 200 >= 000 owner-x >= group-x >= world-x : bitwise and-masked with &0111 => 111 >= 110 >= 100 >= 000

Returns:
true if first FsAction is more permissive than the second, false if not.

validateExecuteBitPresentIfReadOrWrite

public static boolean validateExecuteBitPresentIfReadOrWrite(org.apache.hadoop.fs.permission.FsAction perms)
Ensure that read or write permissions are not granted without also granting execute permissions. Essentially, r-- , rw- and -w- are invalid, r-x, -wx, rwx, ---, --x are valid

Parameters:
perms - The FsAction to verify
Returns:
true if the presence of read or write permission is accompanied by execute permissions

getJobTrackerDelegationToken

public static org.apache.hadoop.security.token.Token<org.apache.hadoop.mapreduce.security.token.delegation.DelegationTokenIdentifier> getJobTrackerDelegationToken(org.apache.hadoop.conf.Configuration conf,
                                                                                                                                                                   java.lang.String userName)
                                                                                                                                                            throws java.lang.Exception
Throws:
java.lang.Exception

cancelJobTrackerDelegationToken

public static void cancelJobTrackerDelegationToken(java.lang.String tokenStrForm,
                                                   java.lang.String tokenSignature)
                                            throws java.lang.Exception
Throws:
java.lang.Exception

extractThriftToken

public static org.apache.hadoop.security.token.Token<? extends org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier> extractThriftToken(java.lang.String tokenStrForm,
                                                                                                                                                                 java.lang.String tokenSignature)
                                                                                                                                                          throws org.apache.hadoop.hive.metastore.api.MetaException,
                                                                                                                                                                 org.apache.thrift.TException,
                                                                                                                                                                 java.io.IOException
Throws:
org.apache.hadoop.hive.metastore.api.MetaException
org.apache.thrift.TException
java.io.IOException

extractJobTrackerToken

public static org.apache.hadoop.security.token.Token<org.apache.hadoop.mapreduce.security.token.delegation.DelegationTokenIdentifier> extractJobTrackerToken(java.lang.String tokenStrForm,
                                                                                                                                                             java.lang.String tokenSignature)
                                                                                                                                                      throws org.apache.hadoop.hive.metastore.api.MetaException,
                                                                                                                                                             org.apache.thrift.TException,
                                                                                                                                                             java.io.IOException
Throws:
org.apache.hadoop.hive.metastore.api.MetaException
org.apache.thrift.TException
java.io.IOException

logStackTrace

public static void logStackTrace(org.apache.commons.logging.Log logger)
Logging stack trace

Parameters:
logger -

logHiveConf

public static void logHiveConf(org.apache.commons.logging.Log logger,
                               org.apache.hadoop.hive.conf.HiveConf hc)
debug log the hive conf

Parameters:
logger -
hc -

logList

public static void logList(org.apache.commons.logging.Log logger,
                           java.lang.String itemName,
                           java.util.List<? extends java.lang.Object> list)

logMap

public static void logMap(org.apache.commons.logging.Log logger,
                          java.lang.String itemName,
                          java.util.Map<? extends java.lang.Object,? extends java.lang.Object> map)

logEntrySet

public static void logEntrySet(org.apache.commons.logging.Log logger,
                               java.lang.String itemName,
                               java.util.Set<? extends java.util.Map.Entry> entrySet)

logAllTokens

public static void logAllTokens(org.apache.commons.logging.Log logger,
                                org.apache.hadoop.mapreduce.JobContext context)
                         throws java.io.IOException
Throws:
java.io.IOException

logToken

public static void logToken(org.apache.commons.logging.Log logger,
                            java.lang.String itemName,
                            org.apache.hadoop.security.token.Token<? extends org.apache.hadoop.security.token.TokenIdentifier> t)
                     throws java.io.IOException
Throws:
java.io.IOException