Bladeren bron

HUE-5825 [editor] Downloading a query result might have double extensions

Romain Rigaux 8 jaren geleden
bovenliggende
commit
d7b87b4788

+ 1 - 1
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -1220,7 +1220,7 @@ ${ assist.assistPanel() }
           name = wizard.prefill.target_path ? wizard.prefill.target_path() + '.' : '';
         }
 
-        return name.replace(' ', '_');
+        return name.replace(/ /g, '_').toLowerCase();
       });
       self.defaultName.subscribe(function(newVal) {
         vm.createWizard.destination.name(newVal);

+ 6 - 2
desktop/libs/notebook/src/notebook/connectors/base.py

@@ -17,6 +17,7 @@
 
 import json
 import logging
+import re
 import uuid
 
 from django.utils.translation import ugettext as _
@@ -292,5 +293,8 @@ class Api(object):
   def statement_similarity(self, notebook, snippet, source_platform, target_platform): raise NotImplementedError()
 
 
-def _get_snippet_name(notebook):
-  return (('%(name)s' if notebook.get('name') else '%(type)s-%(id)s') % notebook).replace('-', '_')
+def _get_snippet_name(notebook, unique=False, table_format=False):
+  name = (('%(name)s' + ('%(id)s' if unique else '') if notebook.get('name') else '%(type)s-%(id)s') % notebook)
+  if table_format:
+    name = re.sub('-|\s', '_', name)
+  return name

+ 2 - 2
desktop/libs/notebook/src/notebook/connectors/hiveserver2.py

@@ -353,7 +353,7 @@ class HS2Api(Api):
       # Test handle to verify if still valid
       db.fetch(handle, start_over=True, rows=1)
 
-      file_name = '%s.%s' % (_get_snippet_name(notebook), format)
+      file_name = _get_snippet_name(notebook)
 
       return data_export.download(handle, format, db, id=snippet['id'], file_name=file_name)
     except Exception, e:
@@ -502,7 +502,7 @@ ALTER TABLE `%(table)s` SET TBLPROPERTIES('EXTERNAL'='TRUE');
 
 DROP TABLE IF EXISTS `%(table)s`;
     ''' % {
-      'table': _get_snippet_name(notebook),
+      'table': _get_snippet_name(notebook, unique=True, table_format=True),
       'location': destination,
       'hql': query.hql_query
     }

+ 1 - 1
desktop/libs/notebook/src/notebook/views.py

@@ -181,7 +181,7 @@ def execute_and_watch(request):
     editor = make_notebook(name='Execute and watch', editor_type=editor_type, statement=sql, status='ready-execute', database=snippet['database'], on_success_url=success_url)
   elif action == 'index_query':
     if destination == '__hue__':
-      destination = _get_snippet_name(notebook)
+      destination = _get_snippet_name(notebook, unique=True, table_format=True)
       live_indexing = True
     else:
       live_indexing = False