瀏覽代碼

HUE-3228 [dashboard] Display fetched record by get_document

Romain Rigaux 8 年之前
父節點
當前提交
f0326c9
共有 3 個文件被更改,包括 13 次插入13 次删除
  1. 10 11
      apps/impala/src/impala/dashboard_api.py
  2. 1 1
      apps/search/src/search/api.py
  3. 2 1
      desktop/libs/libsolr/src/libsolr/api.py

+ 10 - 11
apps/impala/src/impala/dashboard_api.py

@@ -228,14 +228,17 @@ class SQLApi():
       }
 
 
-  def get(self, db_table, doc_id):
-    database, table = self._get_database_table_names(db_table)
+  def get(self, dashboard, doc_id):
+    database, table = self._get_database_table_names(dashboard['name'])
+    field = self._get_field(dashboard, dashboard['idField'])
+    quotes = '' if self._is_number(field['type']) else "'" 
 
-    sql = "SELECT * FROM `%(database)s`.`%(table)s` WHERE %(pk)s = %(doc_id)s" % {
+    sql = "SELECT * FROM `%(database)s`.`%(table)s` WHERE `%(idField)s` = %(quotes)s%(doc_id)s%(quotes)s" % {
       'database': database,
       'table': table,
-      'pk': doc_id,
-      'doc_id': doc_id
+      'idField': dashboard['idField'], # Only 1 PK currently,
+      'doc_id': doc_id,
+      'quotes': quotes
     }
 
     result = self._sync_execute(sql, database)
@@ -243,16 +246,12 @@ class SQLApi():
     if result:    
       cols = [col['name'] for col in result['meta']]
       rows = list(result['data']) # No escape_rows
-      doc_data = [dict((header, cell) for header, cell in zip(cols, row)) for row in rows]
+      doc_data = dict([(header, cell) for row in rows for header, cell in zip(cols, row)])
     else:
       doc_data = {}
 
     return {
-      "status": 0,
-      "doc": {
-        "doc": doc_data
-      },
-      "message": ""
+      "doc": doc_data
     }
 
   def _sync_execute(self, sql, database):

+ 1 - 1
apps/search/src/search/api.py

@@ -153,7 +153,7 @@ def get_document(request):
     doc_id = request.POST.get('id')
 
     if doc_id:
-      result['doc'] = get_engine(request.user, collection).get(collection['name'], doc_id)
+      result['doc'] = get_engine(request.user, collection).get(collection, doc_id)
       if result['doc']['doc']:
         result['status'] = 0
         result['message'] = ''

+ 2 - 1
desktop/libs/libsolr/src/libsolr/api.py

@@ -604,12 +604,13 @@ class SolrApi(object):
       raise PopupException(e, title=_('Error while accessing Solr'))
 
   def get(self, core, doc_id):
+    collection_name = core['name']
     try:
       params = self._get_params() + (
           ('id', doc_id),
           ('wt', 'json'),
       )
-      response = self._root.get('%(core)s/get' % {'core': core}, params=params)
+      response = self._root.get('%(core)s/get' % {'core': collection_name}, params=params)
       return self._get_json(response)
     except RestException, e:
       raise PopupException(e, title=_('Error while accessing Solr'))