Explorar o código

HUE-721 [beeswax] Save results as a table is broken

Bug created in HUE-703 and fixed here.
Fix call back bug from HUE-688.
Romain Rigaux %!s(int64=13) %!d(string=hai) anos
pai
achega
8f1cdd05dd

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

@@ -709,7 +709,7 @@ def query_done_cb(request, server_id):
   """
   res = HttpResponse('<html><head></head><body></body></html>')
 
-  history = authorized_get_history(request, server_id)
+  history = models.QueryHistory.objects.get(server_id=server_id)
 
   if history is None:
     LOG.error('Processing query completion email: Cannot find query matching id %s' % (server_id,))
@@ -1002,7 +1002,7 @@ def save_results(request, id):
                       'Saving results from a table to a directory is not supported. '
                       'You may copy from the HDFS location manually.')
           target_dir = form.cleaned_data['target_dir']
-          request.fs.rename(result_meta.table_dir, target_dir)
+          request.fs.rename_star(result_meta.table_dir, target_dir)
           LOG.debug("Moved results from %s to %s" % (result_meta.table_dir, target_dir))
           query_history.save_state(models.QueryHistory.STATE.expired)
           fb_url = location_to_url(request, target_dir, strict=False)
@@ -1082,7 +1082,7 @@ def _save_results_ctas(request, query_history, target_table, result_meta):
     # 2. Move the results into the table's storage
     table_obj = db_utils.meta_client().get_table("default", target_table)
     table_loc = request.fs.urlsplit(table_obj.sd.location)[2]
-    request.fs.rename(result_meta.table_dir, table_loc)
+    request.fs.rename_star(result_meta.table_dir, table_loc)
     LOG.debug("Moved results from %s to %s" % (result_meta.table_dir, table_loc))
     request.flash.put('Saved query results as new table %s' % (target_table,))
     query_history.save_state(models.QueryHistory.STATE.expired)

+ 11 - 0
desktop/libs/hadoop/src/hadoop/fs/webhdfs.py

@@ -279,6 +279,17 @@ class WebHdfs(Hdfs):
       raise IOError("Rename failed: %s -> %s" %
                     (smart_str(old), smart_str(new)))
 
+  def rename_star(self, old_dir, new_dir):
+    """Equivalent to `mv old_dir/* new"""
+    if not self.isdir(old_dir):
+      raise IOError(errno.ENOTDIR, "'%s' is not a directory" % (old_dir,))
+    if not self.exists(new_dir):
+      self.mkdir(new_dir)
+    elif not self.isdir(new_dir):
+      raise IOError(errno.ENOTDIR, "'%s' is not a directory" % (new_dir,))
+    ls = self.listdir(old_dir)
+    for dirent in ls:
+      self.rename(Hdfs.join(old_dir, dirent), Hdfs.join(new_dir, dirent))
 
   def chown(self, path, user=None, group=None):
     """chown(path, user=None, group=None)"""