Преглед изворни кода

HUE-5145 [metadata] Add skeleton of table_details API

Romain Rigaux пре 9 година
родитељ
комит
a1729b3

+ 3 - 0
desktop/libs/metadata/src/metadata/navigator_client_tests.py

@@ -76,3 +76,6 @@ class TestNavigatorclient:
     # "ca es"
     # ca OR es
     # tags:a
+
+    # type:table tax
+    # owner:romain ca

+ 2 - 2
desktop/libs/metadata/src/metadata/optimizer_api.py

@@ -29,7 +29,6 @@ from desktop.models import Document2
 from notebook.models import Notebook
 
 from metadata.optimizer_client import OptimizerApi
-from metadata.conf import OPTIMIZER
 
 
 LOG = logging.getLogger(__name__)
@@ -103,11 +102,12 @@ def top_tables(request):
 def table_details(request):
   response = {'status': -1}
 
+  database_name = request.POST.get('databaseName')
   table_name = request.POST.get('tableName')
 
   api = OptimizerApi()
 
-  data = api.table_details(table_name=table_name)
+  data = api.table_details(database_name=database_name, table_name=table_name)
 
   if data['status'] == 'success':
     response['status'] = 0

+ 8 - 40
desktop/libs/metadata/src/metadata/optimizer_client.py

@@ -45,7 +45,7 @@ def is_optimizer_enabled():
   return get_optimizer_url() and OPTIMIZER.PRODUCT_NAME.get()
 
 
-class OptimizerApiException(Exception):
+class OptimizerApiException(PopupException):
   pass
 
 
@@ -93,7 +93,7 @@ class OptimizerApi(object):
         LOG.info('Upload command is successful despite return code of 1: %s' % e.output)
         data = '\n'.join(e.output.split('\n')[3:]) # Beware removing of {"url":...}
     except RestException, e:
-      raise PopupException(e, title=_('Error while accessing Optimizer'))
+      raise OptimizerApiException(e, title=_('Error while accessing Optimizer'))
 
     if data:
       response = json.loads(data) 
@@ -105,31 +105,6 @@ class OptimizerApi(object):
     return self._exec('get-tenant', ['--email', email])
 
 
-  def create_product(self, product_name=None, product_secret=None, authCode=None):
-    try:
-      data = {
-          'productName': product_name if product_name is not None else self._product_name,
-          'productSecret': product_secret if product_secret is not None else self._product_secret,
-          'authCode': authCode if authCode is not None else self._product_auth_secret
-      }
-      return self._root.post('/api/createProduct', data=json.dumps(data), contenttype=_JSON_CONTENT_TYPE)
-    except RestException, e:
-      raise PopupException(e, title=_('Error while accessing Optimizer'))
-
-
-  def add_email_to_product(self, email=None, email_password=None):
-    try:
-      data = {
-          'productName': self._product_name,
-          'productSecret': self._product_secret,
-          'email': email if email is not None else self._email,
-          'password': email_password if email_password is not None else self._email_password
-      }
-      return self._root.post('/api/addEmailToProduct', data=json.dumps(data), contenttype=_JSON_CONTENT_TYPE)
-    except RestException, e:
-      raise PopupException(e, title=_('Error while accessing Optimizer'))
-
-
   def authenticate(self):
     try:
       data = {
@@ -199,19 +174,12 @@ class OptimizerApi(object):
     return self._exec('get-top-tables', ['--tenant', self._product_name])
 
 
-  def table_details(self, table_name, token=None, email=None):
-    if token is None:
-      token = self._authenticate()
-
-    try:
-      data = {
-          'email': email if email is not None else self._email,
-          'token': token,
-          'tableName': table_name
-      }
-      return self._root.post('/api/tableDetails', data=json.dumps(data), contenttype=_JSON_CONTENT_TYPE)
-    except RestException, e:
-      raise PopupException(e, title=_('Error while accessing Optimizer'))
+  def table_details(self, database_name, table_name):
+    return self._exec('get-tables-detail', [
+        '--tenant', self._product_name,
+        '--db-name', database_name,
+        '--table-name', table_name
+    ])
 
 
   def query_compatibility(self, source_platform, target_platform, query, token=None, email=None):

+ 4 - 17
desktop/libs/metadata/src/metadata/optimizer_client_tests.py

@@ -63,17 +63,6 @@ class TestOptimizerApi(object):
 
     assert_equal('success', resp['status'], resp)
 
-  def test_create_product(self):
-    resp = self.api.create_product()
-
-    assert_equal('success', resp['status'], resp)
-
-
-  def test_add_email_to_product(self):
-    resp = self.api.add_email_to_product()
-
-    assert_equal('success', resp['status'], resp)
-
 
   def test_authenticate(self):
     resp = self.api.authenticate()
@@ -107,7 +96,7 @@ class TestOptimizerApi(object):
     queries = [
         "select emps.id from emps where emps.name = 'Joe' group by emps.mgr, emps.id;",
         "select emps.name from emps where emps.num = 007 group by emps.state, emps.name;",
-        "select Part.partkey, Part.name, Part.type from Part where Part.yyprice > 2095",
+        "select Part.partkey, Part.name, Part.type from db1.Part where Part.yyprice > 2095",
         "select Part.partkey, Part.name, Part.mfgr FROM Part WHERE Part.name LIKE '%red';",
         "select count(*) as loans from account a where a.account_state_id in (5,9);",
         "select orders.key, orders.id from orders where orders.price < 9999",
@@ -125,12 +114,10 @@ class TestOptimizerApi(object):
 
 
   def test_table_details(self):  # Requires test_upload to run before
-    resp = self.api.authenticate()
-    token = resp['token']
-
-    resp = self.api.popular_values(table_name='Part', token=token)
-    resp = self.api.popular_values(table_name='Part', column_name='partkey', token=token)
+    resp = self.api.table_details(table_name='default', table_name='emps')
+    assert_equal('success', resp['status'], resp)
 
+    resp = self.api.table_details(table_name='db1', table_name='Part')
     assert_equal('success', resp['status'], resp)