Skip to content

Commit f292cb3

Browse files
[computes] fixed session-type extraction for connectors
The problem is that connector based query execution is not able to reuse session to fetch results. The frontend is sending the correct session_id but our session fetching logic got broken when the computes was implemented. we are now looking for the session_type from compute['name'] for computes, connector['name'] for connector and then snippets['type'] for old config file based hive/impala sessions. A related change is to make use of session for get_log and check_status calls if the frontend is sending it. Rest is some ruff and other refactoring.
1 parent 9e27d5f commit f292cb3

File tree

7 files changed

+208
-244
lines changed

7 files changed

+208
-244
lines changed

apps/beeswax/src/beeswax/common.py

+27-13
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
"""
2121
from __future__ import print_function
2222

23-
import numbers
2423
import re
2524
import time
25+
import numbers
2626

2727
from django import forms
2828

29-
from beeswax.models import Namespace, Compute
29+
from beeswax.models import Compute, Namespace
3030

31-
HIVE_IDENTIFER_REGEX = re.compile("(^[a-zA-Z0-9]\w*\.)?[a-zA-Z0-9]\w*$")
31+
HIVE_IDENTIFER_REGEX = re.compile(r"(^[a-zA-Z0-9]\w*\.)?[a-zA-Z0-9]\w*$")
3232

3333
DL_FORMATS = ['csv', 'xls']
3434

@@ -56,12 +56,13 @@
5656
(' ', "Space", 32),
5757
]
5858

59+
5960
def timing(fn):
6061
def decorator(*args, **kwargs):
6162
time1 = time.time()
6263
ret = fn(*args, **kwargs)
6364
time2 = time.time()
64-
print('%s elapsed time: %0.3f ms' % (fn.__name__, (time2-time1)*1000.0))
65+
print('%s elapsed time: %0.3f ms' % (fn.__name__, (time2 - time1) * 1000.0))
6566
return ret
6667
return decorator
6768

@@ -79,7 +80,8 @@ def apply_natural_sort(collection, key=None):
7980
Applies a natural sort (http://rosettacode.org/wiki/Natural_sorting) to a list or dictionary
8081
Dictionary types require a sort key to be specified
8182
"""
82-
to_digit = lambda i: int(i) if i.isdigit() else i
83+
def to_digit(i):
84+
return int(i) if i.isdigit() else i
8385

8486
def tokenize_and_convert(item, key=None):
8587
if key:
@@ -89,13 +91,26 @@ def tokenize_and_convert(item, key=None):
8991
return sorted(collection, key=lambda i: tokenize_and_convert(i, key=key))
9092

9193

92-
def is_compute(cluster):
94+
def find_compute_in_cluster(cluster):
9395
if not cluster:
94-
return False
96+
return None
9597
connector = cluster.get('connector')
9698
compute = cluster.get('compute')
97-
compute_check = lambda x: x and x.get('type') in COMPUTE_TYPES
98-
return compute_check(cluster) or compute_check(connector) or compute_check(compute)
99+
100+
def _compute_check(x):
101+
return x and x.get('type') in COMPUTE_TYPES
102+
103+
return (
104+
cluster if _compute_check(cluster)
105+
else compute if _compute_check(compute)
106+
else connector if _compute_check(connector) else None)
107+
108+
109+
def extract_session_type(snippet):
110+
compute = find_compute_in_cluster(snippet)
111+
if compute and compute.get('name'):
112+
return compute['name']
113+
return snippet.get('type') if snippet else None
99114

100115

101116
'''
@@ -107,17 +122,16 @@ def is_compute(cluster):
107122
3. Lookup namespace based on dialect from cluster or prpvided dialect
108123
and return the first compute filtered by user-access. Needs valid user
109124
'''
125+
126+
110127
def find_compute(cluster=None, user=None, dialect=None, namespace_id=None):
111128
if cluster:
112129
# If we find a full/partial cluster object, we will attempt to load a compute
113130
connector = cluster.get('connector')
114131
compute = cluster.get('compute')
115-
compute_check = lambda x: x and x.get('type') in COMPUTE_TYPES
116132

117133
# Pick the most probable compute object
118-
selected_compute = (cluster if compute_check(cluster)
119-
else compute if compute_check(compute)
120-
else connector if compute_check(connector) else None)
134+
selected_compute = find_compute_in_cluster(cluster)
121135

122136
# If found, we will attempt to reload it, first by id then by name
123137
if selected_compute:

0 commit comments

Comments
 (0)