Browse Source

HUE-4866 [editor] Integrate file content into the query statement

Romain Rigaux 9 years ago
parent
commit
79e003d

+ 7 - 4
desktop/libs/notebook/src/notebook/connectors/hiveserver2.py

@@ -222,12 +222,15 @@ class HS2Api(Api):
 
     statement = self._get_current_statement(db, snippet)
     session = self._get_session(notebook, snippet['type'])
+
     if snippet.get('statementType') == 'file':
-      query_s = ''
-    else:
-      query_s = statement['statement']
+      script_path = snippet['statementPath']
+      if script_path:
+        script_path = script_path.replace('hdfs://', '')
+        if self.request.fs.do_as_user(self.user, self.request.fs.exists, script_path):
+          statement['statement'] = self.request.fs.do_as_user(self.user, self.request.fs.read, script_path, 0, 16 * 1024 ** 2)
 
-    query = self._prepare_hql_query(snippet, query_s, session)
+    query = self._prepare_hql_query(snippet, statement['statement'], session)
 
     try:
       if statement.get('statement_id') == 0:

+ 5 - 2
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -725,7 +725,9 @@ var EditorViewModel = (function() {
         id: self.id,
         type: self.type,
         status: self.status,
+        statementType: self.statementType,
         statement: self.statement,
+        statementPath: self.statementPath,
         properties: self.properties,
         result: self.result.getContext(),
         database: self.database,
@@ -778,12 +780,13 @@ var EditorViewModel = (function() {
 
     self.wasBatchExecuted = ko.observable(typeof snippet.wasBatchExecuted != "undefined" && snippet.wasBatchExecuted != null ? snippet.wasBatchExecuted : false);
     self.isReady = ko.computed(function() {
-      return (['jar', 'java', 'spark2', 'distcp'].indexOf(self.type()) == -1 && self.statement() !== '') ||
+      return (self.statementType() == 'text' && (['jar', 'java', 'spark2', 'distcp'].indexOf(self.type()) == -1 && self.statement() !== '') ||
         (['jar', 'java'].indexOf(self.type()) != -1 && (self.properties().app_jar() != '' && self.properties().class() != '')) ||
         (['spark2'].indexOf(self.type()) != -1 && self.properties().jars().length > 0) ||
         (['shell'].indexOf(self.type()) != -1 && self.properties().command_path().length > 0) ||
         (['mapreduce'].indexOf(self.type()) != -1 && self.properties().app_jar().length > 0) ||
-        (['distcp'].indexOf(self.type()) != -1 && self.properties().source_path().length > 0 && self.properties().destination_path().length > 0);
+        (['distcp'].indexOf(self.type()) != -1 && self.properties().source_path().length > 0 && self.properties().destination_path().length > 0)) ||
+        (self.statementType() == 'file' && self.statementPath().length > 0);
     });
     self.lastExecuted = ko.observable(typeof snippet.lastExecuted != "undefined" && snippet.lastExecuted != null ? snippet.lastExecuted : 0);
 

+ 1 - 1
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1548,7 +1548,7 @@ ${ hueIcons.symbols() }
     <div class="editor span12" data-bind="css: {'single-snippet-editor ace-container-resizable' : $root.editorMode() }, clickForAceFocus: ace">
       <!-- ko if: statementType() != 'text' -->
         <div class="control-group">
-          <label class="control-label">${_('Path')}</label>
+          <label class="control-label">${_('Query Path')}</label>
           <div class="controls">
             <input type="text" class="input-xxlarge filechooser-input" data-bind="value: statementPath, valueUpdate: 'afterkeydown', filechooser: statementPath" placeholder="${ _('Path to query, e.g. /user/hue/sample.sql, s3a:///hue/sample.sql') }"/>
             <!-- ko if: statementPath() -->