Browse Source

[core] Fixed the compute selection logic for query exec

There are multiple different ways that the various calls from UI pass
the compute information. Sometimes, it is a compute, other times it
is a connector etc. This change looks at config. So, if computes are
enabled then look up for compute in snippet, if connectors are
enabled then look for connector in snippet. If none of these are found,
then fallback to the default mechanism of picking up interpreter as
defined in the hue.ini

This bug got introduced in the earlier commit 283676c. Also, reverted
the unneeded change to connectors/base_test.py from that commit.

Change-Id: I8148f7dbf031c329f738ed94ba073161d8d8b4df
Amit Srivastava 2 years ago
parent
commit
077636750e

+ 12 - 7
desktop/libs/notebook/src/notebook/connectors/base.py

@@ -432,16 +432,21 @@ def get_api(request, snippet):
   connector_name = snippet['type']
   connector_name = snippet['type']
 
 
   if has_connectors() and snippet.get('type') == 'hello' and is_admin(request.user):
   if has_connectors() and snippet.get('type') == 'hello' and is_admin(request.user):
+    LOG.debug('Using the interpreter from snippet')
     interpreter = snippet.get('interpreter')
     interpreter = snippet.get('interpreter')
-  else:
+  elif get_cluster_config(request.user).get('has_computes'):
+    if snippet.get('type') in ('hive-compute', 'impala-compute') and snippet.get('id'):
+      LOG.debug("Loading the compute from db using snippet['id']: %" % snippet['id'])
+      interpreter = Compute.objects.get(id=snippet['id']).to_dict()
     if snippet.get('compute'):
     if snippet.get('compute'):
+      LOG.debug("Using the compute as is from snippet['compute']")
       interpreter = snippet['compute']
       interpreter = snippet['compute']
-    elif snippet.get('connector'):
-      interpreter = snippet['connector']
-    elif snippet.get('type') in ('hive-compute', 'impala-compute'):
-      interpreter = Compute.objects.get(id=snippet['id']).to_dict()
-    else:
-      interpreter = get_interpreter(connector_type=connector_name, user=request.user)
+  elif has_connectors() and snippet.get('connector'):
+    LOG.debug("Connectors are enabled and picking the connector from snippet['connector']")
+    interpreter = snippet['connector']
+  else:
+    LOG.debug("Picking up the connectors from the configs using connector_name: %s" % connector_name)
+    interpreter = get_interpreter(connector_type=connector_name, user=request.user)
 
 
   interface = interpreter['interface']
   interface = interpreter['interface']
 
 

+ 1 - 1
desktop/libs/notebook/src/notebook/connectors/base_tests.py

@@ -44,7 +44,7 @@ class TestNotebook(object):
   def test_get_api(self):
   def test_get_api(self):
     request = Mock()
     request = Mock()
     snippet = {
     snippet = {
-      'connector': {'optimizer': 'api', 'interface': 'hiveserver2', 'type': 'hive-compute', 'dialect': 'hive'},
+      'connector': {'optimizer': 'api'},
       'type': 'hive'  # Backward compatibility
       'type': 'hive'  # Backward compatibility
     }
     }