Эх сурвалжийг харах

HUE-1006 [beeswax] Support download of large files

Tell to save into HDFS in did you know.
Romain Rigaux 12 жил өмнө
parent
commit
b58f58f

+ 7 - 0
apps/beeswax/src/beeswax/forms.py

@@ -100,6 +100,7 @@ class SaveResultsForm(DependencyAwareForm):
 
   def __init__(self, *args, **kwargs):
     self.db = kwargs.pop('db', None)
+    self.fs = kwargs.pop('fs', None)
     super(SaveResultsForm, self).__init__(*args, **kwargs)
 
   def clean(self):
@@ -115,6 +116,12 @@ class SaveResultsForm(DependencyAwareForm):
           del cleaned_data['target_table']
         except Exception:
           pass
+    elif cleaned_data['save_target'] == SaveResultsForm.SAVE_TYPE_DIR:
+      target_dir = cleaned_data['target_dir']
+      if not target_dir.startswith('/'):
+        self._errors['target_dir'] = self.error_class([_('Directory should start with /')])
+      elif self.fs.exists(target_dir):
+        self._errors['target_dir'] = self.error_class([_('Directory already exists')]) # Overwrite destination directory content
 
     return cleaned_data
 

+ 16 - 8
apps/beeswax/src/beeswax/templates/watch_results.mako

@@ -113,8 +113,10 @@ ${layout.menubar(section='query')}
           <div id="jumpToColumnAlert" class="alert hide">
             <button type="button" class="close" data-dismiss="alert">&times;</button>
             <strong>${_('Did you know?')}</strong>
-            ${_('If the result contains a large number of columns, click a row to select a column to jump to.') }
-            ${ _('As you type into the field, a drop-down list displays column names that match the string.')}
+            <ul>
+              <li>${ _('If the result contains a large number of columns, click a row to select a column to jump to') }</li>
+              <li>${ _('Save huge results on HDFS and download them with FileBrowser') }</li>
+            </ul>
           </div>
         </div>
 
@@ -226,20 +228,26 @@ ${layout.menubar(section='query')}
       </label>
       ${comps.field(save_form['target_table'], notitle=True, placeholder=_('Table Name'))}
       <br/>
+
       <label class="radio">
         <input id="id_save_target_1" type="radio" name="save_target" value="to HDFS directory">
         &nbsp;${_('In an HDFS directory')}
       </label>
-      ${comps.field(save_form['target_dir'], notitle=True, hidden=True, placeholder=_('Results location'), klass="pathChooser")}
-      <br/>
-      <br/>
+      <span id="hdfs" class="hide">
+        ${comps.field(save_form['target_dir'], notitle=True, hidden=False, placeholder=_('Results location'), klass="pathChooser input-xlarge")}
+        <br/>
+        <br/>
+        <div class="alert alert-warn">
+          ${ _('In text with columns separated by ^A and rows separated by newlines. JSON for non primitive type columns.') }
+        </div>
+      </span>
       <div id="fileChooserModal" class="smallModal well hide">
         <a href="#" class="close" data-dismiss="modal">&times;</a>
       </div>
     </div>
     <div class="modal-footer">
       <div id="fieldRequired" class="hide" style="position: absolute; left: 10;">
-        <span class="label label-important">${_('Sorry, name is required.')}</span>
+        <span class="label label-important">${_('Name or directory required.')}</span>
       </div>
       <a class="btn" data-dismiss="modal">${_('Cancel')}</a>
       <a id="saveBtn" class="btn btn-primary">${_('Save')}</a>
@@ -278,12 +286,12 @@ $(document).ready(function () {
     $("input[name='target_table']").removeClass("fieldError");
     if ($(this).val().indexOf("HDFS") > -1) {
       $("input[name='target_table']").addClass("hide");
-      $("input[name='target_dir']").removeClass("hide");
+      $("#hdfs").removeClass("hide");
       $(".fileChooserBtn").removeClass("hide");
     }
     else {
       $("input[name='target_table']").removeClass("hide");
-      $("input[name='target_dir']").addClass("hide");
+      $("#hdfs").addClass("hide");
       $(".fileChooserBtn").addClass("hide");
     }
   });

+ 6 - 0
apps/beeswax/src/beeswax/tests.py

@@ -775,6 +775,12 @@ for x in sys.stdin:
       self.cluster.fs.mkdir(TARGET_DIR_ROOT)
       self.cluster.fs.chown(TARGET_DIR_ROOT, user='test')
 
+    # Already existing dir
+    hql = "SELECT * FROM test"
+    resp = _make_query(self.client, hql, wait=True, local=False, max=180.0)
+    resp = save_and_verify(resp, TARGET_DIR_ROOT, verify=False)
+    assert_true('Directory already exists' in resp.content, resp.content)
+
     # SELECT *. (Result dir is same as table dir.)
     hql = "SELECT * FROM test"
     resp = _make_query(self.client, hql, wait=True, local=False, max=180.0)

+ 1 - 1
apps/beeswax/src/beeswax/views.py

@@ -706,7 +706,7 @@ def save_results(request, id):
       raise PopupException(msg)
 
     db = dbms.get(request.user, query_history.get_query_server_config())
-    form = beeswax.forms.SaveResultsForm(request.POST, db=db)
+    form = beeswax.forms.SaveResultsForm(request.POST, db=db, fs=request.fs)
 
     if request.POST.get('cancel'):
       return format_preserving_redirect(request, '/%s/watch/%s' % (app_name, id))