浏览代码

HUE-5119 [oozie] Offer file output path to Hive query batch

Romain Rigaux 9 年之前
父节点
当前提交
63bfbfa

+ 4 - 9
apps/oozie/src/oozie/models2.py

@@ -441,8 +441,7 @@ class Workflow(Job):
     tmpl = 'editor2/gen/workflow.xml.mako'
 
     data = self.get_data()
-    nodes = [node for node in self.nodes if node.name != 'End'] + [node for node in self.nodes if
-                                                                   node.name == 'End']  # End at the end
+    nodes = [node for node in self.nodes if node.name != 'End'] + [node for node in self.nodes if node.name == 'End']  # End at the end
     node_mapping = dict([(node.id, node) for node in nodes])
     sub_wfs_ids = [node.data['properties']['workflow'] for node in nodes if node.data['type'] == 'subworkflow']
     workflow_mapping = dict(
@@ -863,13 +862,9 @@ class Node():
         self.data['properties']['to'] = self.user.email
         self.data['properties']['subject'] = _("${wf:name()} execution successful")
 
-        if mapping.get('send_result') or True:
-          if self.data['type'] == HiveDocumentAction.TYPE:
-            # Convert SELECT to insert
-            # Add attachment loc
-            pass
-        # If send report link
-        # Convert query to create table if not exist and insert partition
+      if mapping.get('send_result_path'):
+        if self.data['type'] == EndNode.TYPE:  
+          self.data['properties']['body'] = 'View result file at %(send_result_browse_url)s' % mapping
 
     return django_mako.render_to_string(self.get_template_name(), data)
 

+ 1 - 1
apps/oozie/src/oozie/templates/editor2/submit_job_popup.mako

@@ -93,7 +93,7 @@
           ${_('Email not set in ')}<a href="/useradmin/users/edit/${user.username}#step2" target="_blank"> ${_('profile.')} </a>
         % endif
         </label>
-        %endif
+        %endif       
       % if return_json:
         <input type="hidden" name="format" value="json">
       % endif

+ 1 - 0
apps/oozie/src/oozie/views/editor2.py

@@ -432,6 +432,7 @@ def _is_oozie_mail_enabled(user):
   oozie_conf = api.get_configuration()
   return oozie_conf.get('oozie.email.smtp.host') != 'localhost'
 
+
 def _submit_workflow(user, fs, jt, workflow, mapping):
   try:
     submission = Submission(user, workflow, fs, jt, mapping)

+ 16 - 5
desktop/libs/liboozie/src/liboozie/submission2.py

@@ -198,13 +198,24 @@ class Submission(object):
 
           self.job.override_subworkflow_id(action, workflow.id) # For displaying the correct graph
           self.properties['workspace_%s' % workflow.uuid] = workspace # For pointing to the correct workspace
+
         elif action.data['type'] == 'hive-document' or action.data['type'] == 'hive2':
-          if action.data['type'] == 'hive-document' and action.data['properties'].get('uuid'):
-            from notebook.models import Notebook
+          from notebook.models import Notebook
+          if action.data['properties'].get('uuid'):
             notebook = Notebook(document=Document2.objects.get_by_uuid(user=self.user, uuid=action.data['properties']['uuid']))
-            statements = notebook.get_str()
-          else:
-            statements = action.data['properties'].get('statements')
+            #statements = notebook.get_str()
+            statements = '\n\n\n'.join([snippet['statement_raw'] for snippet in notebook.get_data()['snippets']])
+
+          if self.properties.get('send_result_path'):
+            statements = """
+INSERT OVERWRITE DIRECTORY '%s'
+ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
+WITH SERDEPROPERTIES (
+   "separatorChar" = "\t",
+   "quoteChar"     = "'",
+   "escapeChar"    = "\\"
+)  
+STORED AS TEXTFILE %s""" % (self.properties.get('send_result_path'), statements)
 
           if statements is not None:
             self._create_file(deployment_dir, action.data['name'] + '.sql', statements)