本文整理汇总了Python中beeswax.models.QueryHistory.get方法的典型用法代码示例。如果您正苦于以下问题:Python QueryHistory.get方法的具体用法?Python QueryHistory.get怎么用?Python QueryHistory.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类beeswax.models.QueryHistory
的用法示例。
在下文中一共展示了QueryHistory.get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: authorized_get_history
# 需要导入模块: from beeswax.models import QueryHistory [as 别名]
# 或者: from beeswax.models.QueryHistory import get [as 别名]
def authorized_get_history(request, query_history_id, owner_only=False, must_exist=False):
if query_history_id is None and not must_exist:
return None
try:
query_history = QueryHistory.get(id=query_history_id)
except QueryHistory.DoesNotExist:
if must_exist:
raise PopupException(_('QueryHistory %(id)s does not exist.') % {'id': query_history_id})
else:
return None
query_history.design.doc.get().can_read_or_exception(request.user)
return query_history
示例2: handle
# 需要导入模块: from beeswax.models import QueryHistory [as 别名]
# 或者: from beeswax.models.QueryHistory import get [as 别名]
def handle(self, *args, **options):
days = int(args[0]) if len(args) >= 1 else 7
close_all = args[1] == 'all' if len(args) >= 2 else False
self.stdout.write('Closing (all=%s) HiveServer2 queries older than %s days...\n' % (close_all, days))
queries = QueryHistory.objects.filter(last_state__in=[QueryHistory.STATE.expired.value, QueryHistory.STATE.failed.value, QueryHistory.STATE.available.value])
if close_all:
queries = QueryHistory.objects.all()
queries = queries.filter(submission_date__lte=datetime.today() - timedelta(days=days))
import os
import beeswax
from beeswax import conf
from beeswax import hive_site
try:
beeswax.conf.HIVE_CONF_DIR.set_for_testing(os.environ['HIVE_CONF_DIR'])
except:
LOG.exception('failed to lookup HIVE_CONF_DIR in environment')
self.stdout.write('Did you export HIVE_CONF_DIR=/etc/hive/conf?\n')
raise
hive_site.reset()
hive_site.get_conf()
closed_queries = 0
already_closed_queries = 0
for query in queries:
try:
query_history = QueryHistory.get(id=query.id)
if query_history.server_id is not None:
handle = query_history.get_handle()
dbms.get(user=query_history.owner).close_operation(handle)
closed_queries += 1
else:
already_closed_queries += 1
query.last_state = QueryHistory.STATE.expired.value
query.save()
except Exception, e:
if 'None' in str(e) or 'Invalid OperationHandle' in str(e):
already_closed_queries += 1
query.last_state = QueryHistory.STATE.expired.value
query.save()
else:
self.stdout.write('Info: %s\n' % e)
示例3: test_get_runtime_profile
# 需要导入模块: from beeswax.models import QueryHistory [as 别名]
# 或者: from beeswax.models.QueryHistory import get [as 别名]
def test_get_runtime_profile(self):
query = """
SELECT COUNT(1) FROM tweets;
"""
response = _make_query(self.client, query, database=self.DATABASE, local=False, server_name='impala')
content = json.loads(response.content)
query_history = QueryHistory.get(content['id'])
wait_for_query_to_finish(self.client, response, max=180.0)
resp = self.client.post(reverse('impala:get_runtime_profile', kwargs={'query_history_id': query_history.id}))
data = json.loads(resp.content)
assert_equal(0, data['status'], data)
assert_true('Execution Profile' in data['profile'], data)
示例4: authorized_get_query_history
# 需要导入模块: from beeswax.models import QueryHistory [as 别名]
# 或者: from beeswax.models.QueryHistory import get [as 别名]
def authorized_get_query_history(request, query_history_id, owner_only=False, must_exist=False):
if query_history_id is None and not must_exist:
return None
try:
query_history = QueryHistory.get(id=query_history_id)
except QueryHistory.DoesNotExist:
if must_exist:
raise PopupException(_('QueryHistory %(id)s does not exist.') % {'id': query_history_id})
else:
return None
# Some queries don't have a design so are not linked to Document Model permission
if query_history.design is None or not query_history.design.doc.exists():
if not request.user.is_superuser and request.user != query_history.owner:
raise PopupException(_('Permission denied to read QueryHistory %(id)s') % {'id': query_history_id})
else:
query_history.design.doc.get().can_read_or_exception(request.user)
return query_history
示例5: test_basic_flow
# 需要导入模块: from beeswax.models import QueryHistory [as 别名]
# 或者: from beeswax.models.QueryHistory import get [as 别名]
def test_basic_flow(self):
dbs = self.db.get_databases()
assert_true("_impala_builtins" in dbs, dbs)
assert_true(self.DATABASE in dbs, dbs)
tables = self.db.get_tables(database=self.DATABASE)
assert_true("tweets" in tables, tables)
QUERY = """
SELECT * FROM tweets ORDER BY row_num;
"""
response = _make_query(self.client, QUERY, database=self.DATABASE, local=False, server_name="impala")
content = json.loads(response.content)
query_history = QueryHistory.get(content["id"])
response = wait_for_query_to_finish(self.client, response, max=180.0)
results = []
# Check that we multiple fetches get all the result set
while len(results) < 5:
content = fetch_query_result_data(
self.client, response, n=len(results), server_name="impala"
) # We get less than 5 results most of the time, so increase offset
results += content["results"]
assert_equal([1, 2, 3, 4, 5], [col[0] for col in results])
# Check start over
results_start_over = []
while len(results_start_over) < 5:
content = fetch_query_result_data(self.client, response, n=len(results_start_over), server_name="impala")
results_start_over += content["results"]
assert_equal(results_start_over, results)
# Check cancel query
resp = self.client.post(reverse("impala:api_cancel_query", kwargs={"query_history_id": query_history.id}))
content = json.loads(resp.content)
assert_equal(0, content["status"])
示例6: test_get_exec_summary
# 需要导入模块: from beeswax.models import QueryHistory [as 别名]
# 或者: from beeswax.models.QueryHistory import get [as 别名]
def test_get_exec_summary(self):
query = """
SELECT COUNT(1) FROM tweets;
"""
response = _make_query(self.client, query, database=self.DATABASE, local=False, server_name='impala')
content = json.loads(response.content)
query_history = QueryHistory.get(content['id'])
wait_for_query_to_finish(self.client, response, max=180.0)
resp = self.client.post(reverse('impala:get_exec_summary', kwargs={'query_history_id': query_history.id}))
data = json.loads(resp.content)
assert_equal(0, data['status'], data)
assert_true('nodes' in data['summary'], data)
assert_true(len(data['summary']['nodes']) > 0, data['summary']['nodes'])
# Attempt to call get_exec_summary on a closed query
resp = self.client.post(reverse('impala:get_exec_summary', kwargs={'query_history_id': query_history.id}))
data = json.loads(resp.content)
assert_equal(0, data['status'], data)
assert_true('nodes' in data['summary'], data)
assert_true(len(data['summary']['nodes']) > 0, data['summary']['nodes'])