'Returns a Hive thrift client.'

def get_metastore_client(self):

    from thrift.transport import TSocket, TTransport
    from thrift.protocol import TBinaryProtocol
    from hive_service import ThriftHive
    ms = self.metastore_conn
    auth_mechanism = ms.extra_dejson.get('authMechanism', 'NOSASL')
    if (configuration.get('core', 'security') == 'kerberos'):
        auth_mechanism = ms.extra_dejson.get('authMechanism', 'GSSAPI')
        kerberos_service_name = ms.extra_dejson.get('kerberos_service_name', 'hive')
    socket = TSocket.TSocket(ms.host, ms.port)
    if ((configuration.get('core', 'security') == 'kerberos') and (auth_mechanism == 'GSSAPI')):
        try:
            import saslwrapper as sasl
        except ImportError:
            import sasl
        def sasl_factory():
            sasl_client = sasl.Client()
            sasl_client.setAttr('host', ms.host)
            sasl_client.setAttr('service', kerberos_service_name)
            sasl_client.init()
            return sasl_client
        from thrift_sasl import TSaslClientTransport
        transport = TSaslClientTransport(sasl_factory, 'GSSAPI', socket)
    else:
        transport = TTransport.TBufferedTransport(socket)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    return ThriftHive.Client(protocol)
