def get(user, query_server=None): global DBMS_CACHE global DBMS_CACHE_LOCK if query_server is None: cluster_type = Cluster(user).get_type() if cluster_type == IMPALAUI: kwargs = {'name': 'impala'} else: kwargs = {} query_server = get_query_server_config(**kwargs) DBMS_CACHE_LOCK.acquire() try: DBMS_CACHE.setdefault(user.username, {}) if query_server['server_name'] not in DBMS_CACHE[user.username]: # Avoid circular dependency from beeswax.server.hive_server2_lib import HiveServerClientCompatible if query_server['server_name'] == 'impala': from impala.dbms import ImpalaDbms from impala.server import ImpalaServerClient DBMS_CACHE[user.username][ query_server['server_name']] = ImpalaDbms( HiveServerClientCompatible( ImpalaServerClient(query_server, user)), QueryHistory.SERVER_TYPE[1][0]) else: from beeswax.server.hive_server2_lib import HiveServerClient DBMS_CACHE[user.username][ query_server['server_name']] = HiveServer2Dbms( HiveServerClientCompatible( HiveServerClient(query_server, user)), QueryHistory.SERVER_TYPE[1][0]) return DBMS_CACHE[user.username][query_server['server_name']] finally: DBMS_CACHE_LOCK.release()
def get(user, query_server=None, cluster=None): global DBMS_CACHE global DBMS_CACHE_LOCK if query_server is None: query_server = get_query_server_config(connector=cluster) DBMS_CACHE_LOCK.acquire() try: DBMS_CACHE.setdefault(user.id, {}) if query_server['server_name'] not in DBMS_CACHE[user.id]: # Avoid circular dependency from beeswax.server.hive_server2_lib import HiveServerClientCompatible if query_server.get('dialect') == 'impala': from impala.dbms import ImpalaDbms from impala.server import ImpalaServerClient DBMS_CACHE[user.id][query_server['server_name']] = ImpalaDbms( HiveServerClientCompatible(ImpalaServerClient(query_server, user)), QueryHistory.SERVER_TYPE[1][0] ) elif query_server['server_name'] == 'hms': from beeswax.server.hive_metastore_server import HiveMetastoreClient DBMS_CACHE[user.id][query_server['server_name']] = HiveServer2Dbms( HiveMetastoreClient(query_server, user), QueryHistory.SERVER_TYPE[1][0] ) else: from beeswax.server.hive_server2_lib import HiveServerClient DBMS_CACHE[user.id][query_server['server_name']] = HiveServer2Dbms( HiveServerClientCompatible(HiveServerClient(query_server, user)), QueryHistory.SERVER_TYPE[1][0] ) return DBMS_CACHE[user.id][query_server['server_name']] finally: DBMS_CACHE_LOCK.release()